mpv播放影片控制時間問題請教 [論壇 - Ubuntu 影音及遊戲]
正在瀏覽:
1 名遊客
mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/5/9 8:33 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 170
![]() |
在終端機輸入指令以mpv播放影片,例如: mpv -ss=00:01:50 demo.mp4 ,
demo.mp4會從1分50秒開始播,在影片播放中,不結束影片也不用方向鍵跳至特定時間,可用指令方式可控制到特定時間?
2018/11/21 13:46
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/5/9 8:33 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 170
![]() |
試著增加一個 ~/.config/mpv/input.conf 檔案,
cat ~/.config/mpv/input.conf : a seek 00:01:00 absolute # 這樣可做到,按下按鍵a之後,MPV影片即刻會跳到1分鐘處繼續播放, 但是想要做到:按下a按鍵後,可以輸入指定時間,讓影片能到達指定時間播放 ,目前還無解!請高手指教! 上面參考了資料 from: https://github.com/mpv-player/mpv/blob/master/etc/input.conf https://github.com/mpv-player/mpv/blob/master/DOCS/man/input.rst
2018/11/22 9:49
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 36
HP : 179 / 899
![]() |
sclo168 寫到: 目前尚未研究出來您原本想要的功能(上面藍色字) 額外一提,有發現一個類似的功能如下 可以將「滑鼠游標」移到影片下方,就會出現一個「儀表板」, 接著將「滑鼠游標」移到「進度條」,「滑鼠游標」左右移動,就會顯示「影片時間」, 接著按下「滑鼠左鍵」,影片就會跳到該時間開始播放。 我測試的環境是「Ubuntu 18.04」,「mpv 0.27.2」。 以上提供參考 報告完畢 ![]()
2018/11/22 21:40
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/10/7 0:22 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 157
![]() |
查詢Manual page有找到:
--start=<relative time> Seek to given time position. The general format for absolute times is [[hh:]mm:]ss[.ms]. If the time is given with a prefix of + or -, the seek is relative from the start or end of the file. (Since mpv 0.14, the start of the file is always considered 0.) pp% seeks to percent position pp (0-100). #c seeks to chapter number c. (Chapters start from 1.) Examples --start=+56, --start=+00:56 Seeks to the start time + 56 seconds. --start=-56, --start=-00:56 Seeks to the end time - 56 seconds. --start=01:10:00 Seeks to 1 hour 10 min. --start=50% Seeks to the middle of the file. --start=30 --end=40 Seeks to 30 seconds, plays 10 seconds, and exits. --start=-3:20 --length=10 Seeks to 3 minutes and 20 seconds before the end of the file, plays 10 seconds, and exits. --start='#2' --end='#4' Plays chapters 2 and 3, and exits. 實際試驗: mpv --start=00:01:00 Track01.wav 可直接跳到一分鐘的地方開始播放。 Manpage的接續內容也有提到控制播放長度的選項內容,以及結束時間點的方式。 ######### 抱歉,我回完文之後,才發現我會錯意了。 原來是要在播放過程中使用輸入時間的方式跳到特定時間點, 而非用指令列的方式。 ######### 目前有試出粗糙的方向,依據mpv-lua-script上的說明, 寫一個腳本放在~/.config/mpv/scripts/下,內容如下: function something_handler() local timePoint=io.read() local command = "seek " .. timePoint .. " absolute" print(command) mp.command(command) end mp.add_key_binding("b", "something", something_handler) 在播放的時候按b然後輸入時間點完按Enter,是有機會可以跳到指定的時間點。 但常常會有不確定性, 輸入的訊號有時mpv會直接接收,有時可傳到lua的io.read(), 可能因為這是callback的特性之一?
2018/11/22 23:26
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 36
HP : 179 / 899
![]() |
Losepacific 寫到: 我按照您上面提的方式去測試, 關於上面藍色字提到的, 以下簡單紀錄我發現到的現象,提供參考 ================================================================================ 我發現 鍵盤「q」上方的「1」原本就有被「binding」, 鍵盤「w」上方的「2」原本就有被「binding」, 其餘的也有。 ================================================================================ 另外我發現,必須將焦點移到「執行mpv」的「Terminal」那個視窗,這樣就能正常運作。 ================================================================================ 以下是我測試的步驟步驟,簡單做個紀錄 ================================================================================ 先開啟一個「Terminal」。 ================================================================================ 執行下面指令,產生「~/.config/mpv/scripts」這個資料夾
================================================================================ 產生一個檔案「~/.config/mpv/scripts/seek_time_point.lua」 輸入檔案內容如下 function do_seek_time_point() print("do_seek_time_point") local time_point = io.read() print("input: " .. time_point) local command = "seek " .. time_point .. " absolute" print("command: " .. command) mp.command(command) end mp.add_key_binding("k", "seek_time_point", do_seek_time_point) function do_overwrite_keybind_1() print("overwrite_keybind_1") end mp.add_forced_key_binding("1", "overwrite_keybind_1", do_overwrite_keybind_1) ================================================================================ 接著觀看您的影片,舉例執行下面指令
這時候會跳出影片的視窗,並且開始播放影片。 ================================================================================ 接著移動滑鼠,點選剛剛執行「mpv demo.mp4」的那個「Terminal視窗」,將焦點回到「Terminal視窗」。 然後按下「k」,會出現「[seek_time_point] do_seek_time_point」這樣的訊息。 接著就輸入「1:00」,然後按下「Enter」,就會出現如下的訊息
若是還沒按下「k」之前,按下「1」(q上方那個1) 則會出現下面的訊息
================================================================================ 以上測試紀錄,提供參考 報告完畢 ![]() ================================================================================ 額外一提,執行下面指令
顯示
* https://github.com/mpv-player/mpv/tree/master/TOOLS/lua ================================================================================ * https://github.com/mpv-player/mpv/tree/master/player/lua * https://github.com/mpv-player/mpv/tree/master/player/javascript ================================================================================
2018/11/23 5:14
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/5/9 8:33 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 170
![]() |
您真是高手!非常感謝!
是否可將按下按鍵k在播放影片的mpv視窗上面? 之前用指令 xdotool search --sync --onlyvisible --class "mpv" windowactivate key k 可控制目前mpv視窗, 現在再開一個「Terminal視窗」,不知指令如何控制到剛剛執行「mpv demo.mp4」的那個「Terminal視窗」,用指令 xdotool search --sync --onlyvisible --class "terminal" windowactivate key k 無作用, 要如何修改?
2018/11/23 9:29
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/10/7 0:22 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 157
![]() |
剛剛有試出一個繞行的方法,沿用samwhelp大的內容,稍作修改如下:
function do_seek_time_point() print("do_seek_time_point") local f = assert(io.open("/tmp/time_point.txt", "rb")) local time_point = f:read("*line") print("input: " .. time_point) local command = "seek " .. time_point .. " absolute" print("command: " .. command) mp.command(command) end mp.add_key_binding("k", "seek_time_point", do_seek_time_point) 然後,指令的部分: echo "00:01:00" > /tmp/time_point.txt && xdotool search --sync --onlyvisible --class "mpv" windowactivate key k
2018/11/23 13:43
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 36
HP : 179 / 899
![]() |
Losepacific 寫到: 厲害,佩服 感恩各位,這篇讓我又學到新東西了。 讚的拉 ![]()
2018/11/23 13:57
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員二級
![]() ![]() 註冊日期:
2011/5/9 8:33 所屬群組:
已註冊使用者 等級: 7
HP : 0 / 170
![]() |
二位大大真厲害!學到不少!
這樣讓mpv功能大大增強! 再次感謝!
2018/11/23 15:04
|
||||||||||
![]() |
回覆: mpv播放影片控制時間問題請教 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 36
HP : 179 / 899
![]() |
終於可以發文了, 感謝站務人員。
之前不能發文,先貼在另一篇。 現在轉貼回來 以下開始 ================================================================================ 剛剛在觀看「smplayer」的原始碼, 然後執行下面指令,來對照著看 ================================================================================ 先開啟一個「Terminal」,執行下面指令,使用「smplayer」來播放「~/Videos/test.mp4」。
接著在另一個「Terminal」執行下面指令
顯示
上面這段,我之前有在「#1 關於「m3u」和「mpv」和「smplayer」的操作使用」有提到過。 ================================================================================ 接著在上面發現一個參數「--input-file=/dev/stdin」,引起我的注意 一開始先執行「$ man mpv」,使用「--input-file」當關鍵字,找到下面的敘述。 --input-file=<filename> Read commands from the given file. Mostly useful with a FIFO. Since mpv 0.7.0 also understands JSON commands (see JSON IPC), but you can't get replies or events. Use --input-ipc-server for something bi-directional. On MS Windows, JSON commands are not available. This can also specify a direct file descriptor with fd://N (UNIX only). In this case, JSON replies will be written if the FD is writable. NOTE: When the given file is a FIFO mpv opens both ends, so you can do several echo "seek 10" > mp_pipe and the pipe will stay valid. ================================================================================ 接著在網路上找相關文章,在「Google」使用「mpv --input-file」當關鍵字查詢,找到一篇「參考文章」。 ================================================================================ ## 方式一 先開啟一個「Terminal」,執行下面指令
接著開啟另一個「Terminal」,執行下面指令
稍等一下,就會看到「mpv」播放「影片」。 接著回到樓主原本提的需求,執行下面指令
就可以下指令,控制「mpv」從「00:01:00」開始播放影片。 ## 相關參考連結 * $ man mkfifo * https://mpv.io/manual/stable/#options-input-file * https://mpv.io/manual/stable/#command-interface-[relative|absolute|absolute-percent|relative-percent|exact|keyframes] * https://github.com/mpv-player/mpv/blob/master/DOCS/man/options.rst * https://github.com/mpv-player/mpv/blob/master/DOCS/man/input.rst ================================================================================ ## 方式二 先執行下面指令,安裝「socat」
先開啟一個「Terminal」,執行下面指令
接著開啟另一個「Terminal」,執行下面指令
會收到
稍等一下,就會看到「mpv」播放「影片」。 接著回到樓主原本提的需求,執行下面指令
就可以下指令,控制「mpv」從「00:01:00」開始播放影片。 ## 相關參考連結 * https://mpv.io/manual/master/#options-input-ipc-server * https://mpv.io/manual/stable/#command-interface-[relative|absolute|absolute-percent|relative-percent|exact|keyframes] * https://github.com/mpv-player/mpv/blob/master/DOCS/man/options.rst * https://github.com/mpv-player/mpv/blob/master/DOCS/man/input.rst * https://github.com/mpv-player/mpv/blob/master/DOCS/man/ipc.rst ================================================================================ 執行
顯示 ignore seek Time [Flags] [Choice] revert-seek [Flags] quit [Integer] quit-watch-later [Integer] stop frame-step frame-back-step playlist-next [Choice] playlist-prev [Choice] playlist-shuffle sub-step Integer sub-seek Integer print-text String show-text String [Integer] [Integer] expand-text String show-progress sub-add String [Choice] [String] [String] sub-remove [Integer] sub-reload [Integer] tv-last-channel screenshot [Flags] [Choice] screenshot-to-file String [Choice] screenshot-raw [Choice] loadfile String [Choice] Key/value list loadlist String [Choice] playlist-clear playlist-remove Choice playlist-move Integer Integer run String String set String String add String [Double] cycle String [up|down] multiply String Double cycle-values String String String enable-section String [Flags] disable-section String define-section String String [Choice] ab-loop drop-buffers af String String af-command String String String ao-reload vf String String vf-command String String String script-binding String script-message String script-message-to String String overlay-add Integer Integer Integer String Integer String Integer Integer Integer overlay-remove Integer write-watch-later-co hook-add String Integer Integer hook-ack String mouse Integer Integer [Integer] [Choice] keypress String keydown String keyup [String] audio-add String [Choice] [String] [String] audio-remove [Integer] audio-reload [Integer] rescan-external-file [Choice] apply-profile String load-script String ================================================================================ 執行
或是
顯示
================================================================================ 其他範例如下 執行
執行
執行
執行
執行
執行
執行
執行
執行
執行
執行
執行
================================================================================ 上面「方式一」,可以簡化成下面步驟 先開啟一個「Terminal」,執行下面指令
接著執行下面指令
就可以下指令,控制「mpv」從「00:01:00」開始播放影片。 ================================================================================ 以上提供參考, 報告完畢 ![]()
2019/3/13 13:08
|
||||||||||
![]() |
您可以查看帖子.
您不可發帖.
您不可回覆.
您不可編輯自己的帖子.
您不可刪除自己的帖子.
您不可發起投票調查.
您不可在投票調查中投票.
您不可上傳附件.
您不可不經審核直接發帖.