久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='UjVSi'></tfoot>

      <small id='UjVSi'></small><noframes id='UjVSi'>

      <i id='UjVSi'><tr id='UjVSi'><dt id='UjVSi'><q id='UjVSi'><span id='UjVSi'><b id='UjVSi'><form id='UjVSi'><ins id='UjVSi'></ins><ul id='UjVSi'></ul><sub id='UjVSi'></sub></form><legend id='UjVSi'></legend><bdo id='UjVSi'><pre id='UjVSi'><center id='UjVSi'></center></pre></bdo></b><th id='UjVSi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UjVSi'><tfoot id='UjVSi'></tfoot><dl id='UjVSi'><fieldset id='UjVSi'></fieldset></dl></div>

        <bdo id='UjVSi'></bdo><ul id='UjVSi'></ul>

      <legend id='UjVSi'><style id='UjVSi'><dir id='UjVSi'><q id='UjVSi'></q></dir></style></legend>

      在后臺運行一個 ffmpeg 進程

      Run a ffmpeg process in the background(在后臺運行一個 ffmpeg 進程)

          <small id='hmuom'></small><noframes id='hmuom'>

            <tbody id='hmuom'></tbody>
            <bdo id='hmuom'></bdo><ul id='hmuom'></ul>
          • <i id='hmuom'><tr id='hmuom'><dt id='hmuom'><q id='hmuom'><span id='hmuom'><b id='hmuom'><form id='hmuom'><ins id='hmuom'></ins><ul id='hmuom'></ul><sub id='hmuom'></sub></form><legend id='hmuom'></legend><bdo id='hmuom'><pre id='hmuom'><center id='hmuom'></center></pre></bdo></b><th id='hmuom'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hmuom'><tfoot id='hmuom'></tfoot><dl id='hmuom'><fieldset id='hmuom'></fieldset></dl></div>
          • <tfoot id='hmuom'></tfoot>
              <legend id='hmuom'><style id='hmuom'><dir id='hmuom'><q id='hmuom'></q></dir></style></legend>
                本文介紹了在后臺運行一個 ffmpeg 進程的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想在 php 中使用 ffmpeg 將視頻轉換為 .flv.目前我有這個工作,但它會掛起瀏覽器,直到文件上傳并完成.我一直在查看有關如何在后臺運行 exec() 進程的 php 文檔,同時使用返回的 PID 更新進程.這是我發現的:

                I am wanting to use ffmpeg to convert video to .flv in php. Currently I have this working, but it hangs the browser until the file is uploaded and is finished. I have been looking at the php docs on how to run an exec() process in the background, while updating the process using the returned PID. Here is what I found:

                //Run linux command in background and return the PID created by the OS
                function run_in_background($Command, $Priority = 0)
                {
                    if($Priority)
                        $PID = shell_exec("nohup nice -n $Priority $Command > /dev/null & echo $!");
                    else
                        $PID = shell_exec("nohup $Command > /dev/null & echo $!");
                    return($PID);
                }
                

                還有一個技巧,我用它來跟蹤后臺任務是否正在使用返回的 PID 運行:

                There is also a trick which I use to track if the background task is running using the returned PID :

                //Verifies if a process is running in linux
                function is_process_running($PID)
                {
                    exec("ps $PID", $ProcessState);
                    return(count($ProcessState) >= 2);
                }
                

                我是否想創建一個單獨的 .php 文件,然后從 php cli 運行以執行這些功能之一?我只需要一點點推動就可以讓它工作,然后我就可以從那里開始了.

                Am I suppose to create a separate .php file which then runs from the php cli to execute one of these functions? I just need a little nudge in getting this working and then I can take it from there.

                謝謝!

                推薦答案

                我想創建一個單獨的 .php然后從 php cli 運行的文件執行這些功能之一?

                Am I suppose to create a separate .php file which then runs from the php cli to execute one of these functions?

                這可能是我的方式:

                • PHP 網頁在數據庫中添加了一條記錄,表示必須處理此文件"
                  • 并向用戶顯示一條消息;類似于您的文件將很快得到處理"
                  • 首先,將記錄標記為正在處理"
                  • 做 ffmpeg 的事情
                  • 將文件標記為已處理"
                  • 如果它還沒有被處理
                  • 如果正在處理
                  • 或者如果它已經被處理過——然后你可以給他新視頻文件的鏈接.

                  這里有一些其他的想法:

                  Here's a couple of other thoughts :

                  • 當您的應用程序變大時,您可以:
                    • 一個網絡服務器"
                    • 許多處理服務器";在您的應用程序中,ffmpeg 需要大量 CPU,而不是為網頁提供服務;因此,能夠擴展該部分是很好的(這是另一個鎖定"文件,在數據庫中將它們指示為正在處理":這樣,您將不會有多個處理服務器嘗試處理同一個文件)
                    • 繁重/長時間的處理不是網絡服務器的工作!
                    • 如果您想在處理"部分切換到 PHP 以外的其他內容,那會更容易.

                    您的處理腳本"必須每隔幾分鐘啟動一次;如果您使用的是類似 Linux 的機器,您可以使用 cron 來實現這一點.

                    Your "processing script" would have to be launch every couple of minutes ; you can use cron for that, if you are on a Linux-like machine.

                    看到評論后的更多信息

                    由于處理部分是通過 CLI 完成的,而不是來自 Apache,因此您不需要任何背景"操作:您可以使用 shell_exec,當它完成它的工作時,它將把命令的整個輸出返回給你的 PHP 腳本.

                    As the processing part is done from CLI, and not from Apache, you don't need anykind of "background" manipulations : you can just use shell_exec, which will return the whole ouput of the command to your PHP script when it's finished doing it's job.

                    對于觀看網頁的用戶說正在處理",這看起來像是后臺處理;并且,在某種程度上,它會是,因為處理將由另一個進程(甚至可能在另一臺機器上)完成.

                    For the user watching the web page saying "processing", it will seem like background processing ; and, in a way, it'll be, as the processing will be done by another processus (maybe even on another machine).

                    但是,對你來說,它會簡單得多:

                    But, for you, it'll be much simpler :

                    • 一個網頁(沒有背景")
                    • 一個 CLI 腳本,也沒有背景資料.

                    你的處理腳本可能看起來像這樣,我想:

                    Your processing script could look like something like this, I suppose :

                    // Fetch informations from DB about one file to process
                    // and mark it as "processing"
                    
                    // Those would be fetched / determined from the data you just fetched from DB
                    $in_file = 'in-file.avi';
                    $out_file = 'out-file.avi';
                    
                    // Launch the ffmpeg processing command (will probably require more options ^^ )
                    // The PHP script will wait until it's finished : 
                    //   No background work
                    //   No need for any kind of polling
                    $output = shell_exec('ffmpeg ' . escapeshellarg($in_file) . ' ' . escapeshellarg($out_file));
                    
                    // File has been processed
                    // Store the "output name" to DB
                    // Mark the record in DB as "processed"
                    

                    真的比你最初想象的要容易,不是嗎?;-)
                    不要再擔心后臺的東西了:唯一重要的是處理腳本從 crontab 定期啟動.

                    Really easier than what you first thought, isn't it ? ;-)
                    Just don't worry about the background stuff anymore : only thing important is that the processing script is launched regularly, from crontab.


                    希望這會有所幫助:-)


                    Hope this helps :-)

                    這篇關于在后臺運行一個 ffmpeg 進程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                <small id='20GnJ'></small><noframes id='20GnJ'>

                  <i id='20GnJ'><tr id='20GnJ'><dt id='20GnJ'><q id='20GnJ'><span id='20GnJ'><b id='20GnJ'><form id='20GnJ'><ins id='20GnJ'></ins><ul id='20GnJ'></ul><sub id='20GnJ'></sub></form><legend id='20GnJ'></legend><bdo id='20GnJ'><pre id='20GnJ'><center id='20GnJ'></center></pre></bdo></b><th id='20GnJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='20GnJ'><tfoot id='20GnJ'></tfoot><dl id='20GnJ'><fieldset id='20GnJ'></fieldset></dl></div>
                        <tbody id='20GnJ'></tbody>
                          <bdo id='20GnJ'></bdo><ul id='20GnJ'></ul>
                        • <legend id='20GnJ'><style id='20GnJ'><dir id='20GnJ'><q id='20GnJ'></q></dir></style></legend>

                          <tfoot id='20GnJ'></tfoot>
                          主站蜘蛛池模板: 免费一区二区三区 | 国产高清精品一区二区三区 | 欧美日韩久久久 | 三级在线视频 | 亚洲欧美在线观看 | 老外黄色一级片 | 在线看片国产 | 久久久www | 伊人网站在线观看 | 国产精品免费大片 | 国产精品一卡 | 久久com| 亚洲黄色av| 欧美色成人 | 国精产品一品二品国精在线观看 | 91中文字幕在线 | 在线资源视频 | 色视频网站| 欧美国产精品 | 国产精品69毛片高清亚洲 | 日韩午夜电影在线观看 | 亚洲精品18 | 久久久.com | 亚洲电影在线播放 | 日韩久久精品电影 | 欧美激情精品久久久久久 | 国产精品久久久久av | 看av在线 | 天天视频一区二区三区 | 亚洲成人精品免费 | 一区二区三区中文字幕 | 久久综合爱 | 日韩免费 | 蜜臀久久99精品久久久久野外 | av网站在线看 | 欧洲免费视频 | 亚洲成人综合社区 | 91精品综合久久久久久五月天 | 成人免费在线小视频 | 久久久久久亚洲国产精品 | 亚洲网站在线观看 |