mpv播放影片控制時間問題請教 [論壇 - Ubuntu 影音及遊戲]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



mpv播放影片控制時間問題請教
會員二級
註冊日期:
2011/5/9 8:33
所屬群組:
已註冊使用者
等級: 7
HP : 0 / 170
MP : 26 / 5938
EXP: 83
離線
在終端機輸入指令以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
MP : 26 / 5938
EXP: 83
離線
試著增加一個 ~/.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
MP : 666 / 28742
EXP: 96
離線
sclo168 寫到:
試著增加一個 ~/.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



目前尚未研究出來您原本想要的功能(上面藍色字)

額外一提,有發現一個類似的功能如下

可以將「滑鼠游標」移到影片下方,就會出現一個「儀表板」,
接著將「滑鼠游標」移到「進度條」,「滑鼠游標」左右移動,就會顯示「影片時間」,
接著按下「滑鼠左鍵」,影片就會跳到該時間開始播放。


我測試的環境是「Ubuntu 18.04」,「mpv 0.27.2」。

以上提供參考

報告完畢


2018/11/22 21:40
應用擴展 工具箱
回覆: mpv播放影片控制時間問題請教
會員二級
註冊日期:
2011/10/7 0:22
所屬群組:
已註冊使用者
等級: 7
HP : 0 / 157
MP : 23 / 5270
EXP: 28
離線
查詢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
MP : 666 / 28742
EXP: 96
離線
Losepacific 寫到:
#########

抱歉,我回完文之後,才發現我會錯意了。
原來是要在播放過程中使用輸入時間的方式跳到特定時間點,
而非用指令列的方式。

#########

目前有試出粗糙的方向,依據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的特性之一?



我按照您上面提的方式去測試,

關於上面藍色字提到的,

以下簡單紀錄我發現到的現象,提供參考

================================================================================

我發現
鍵盤「q」上方的「1」原本就有被「binding」,
鍵盤「w」上方的「2」原本就有被「binding」,
其餘的也有。

================================================================================

另外我發現,必須將焦點移到「執行mpv」的「Terminal」那個視窗,這樣就能正常運作。

================================================================================

以下是我測試的步驟步驟,簡單做個紀錄

================================================================================

先開啟一個「Terminal」。

================================================================================

執行下面指令,產生「~/.config/mpv/scripts」這個資料夾


$ mkdir -p ~/.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



這時候會跳出影片的視窗,並且開始播放影片。

================================================================================

接著移動滑鼠,點選剛剛執行「mpv demo.mp4」的那個「Terminal視窗」,將焦點回到「Terminal視窗」。

然後按下「k」,會出現「[seek_time_point] do_seek_time_point」這樣的訊息。

接著就輸入「1:00」,然後按下「Enter」,就會出現如下的訊息


[seek_time_point] input: 1:00
[seek_time_point] command: seek 1:00 absolute



若是還沒按下「k」之前,按下「1」(q上方那個1)

則會出現下面的訊息


[seek_time_point] overwrite_keybind_1



================================================================================

以上測試紀錄,提供參考

報告完畢



================================================================================

額外一提,執行下面指令


$ dpkg -L mpv | grep examples



顯示


/usr/share/doc/mpv/examples
/usr/share/doc/mpv/examples/lua
/usr/share/doc/mpv/examples/lua/README.md
/usr/share/doc/mpv/examples/lua/acompressor.lua.gz
/usr/share/doc/mpv/examples/lua/ao-null-reload.lua
/usr/share/doc/mpv/examples/lua/audio-hotplug-test.lua
/usr/share/doc/mpv/examples/lua/autocrop.lua
/usr/share/doc/mpv/examples/lua/autodeint.lua.gz
/usr/share/doc/mpv/examples/lua/autoload.lua.gz
/usr/share/doc/mpv/examples/lua/cycle-deinterlace-pullup.lua
/usr/share/doc/mpv/examples/lua/observe-all.lua
/usr/share/doc/mpv/examples/lua/ontop-playback.lua
/usr/share/doc/mpv/examples/lua/pause-when-minimize.lua
/usr/share/doc/mpv/examples/lua/status-line.lua



* 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
MP : 26 / 5938
EXP: 83
離線
您真是高手!非常感謝!
是否可將按下按鍵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
MP : 23 / 5270
EXP: 28
離線
剛剛有試出一個繞行的方法,沿用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
MP : 666 / 28742
EXP: 96
離線
Losepacific 寫到:
剛剛有試出一個繞行的方法,沿用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:57
應用擴展 工具箱
回覆: mpv播放影片控制時間問題請教
會員二級
註冊日期:
2011/5/9 8:33
所屬群組:
已註冊使用者
等級: 7
HP : 0 / 170
MP : 26 / 5938
EXP: 83
離線
二位大大真厲害!學到不少!
這樣讓mpv功能大大增強!
再次感謝!

2018/11/23 15:04
應用擴展 工具箱
回覆: mpv播放影片控制時間問題請教
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 899
MP : 666 / 28742
EXP: 96
離線
終於可以發文了, 感謝站務人員。

之前不能發文,先貼在另一篇

現在轉貼回來

以下開始

================================================================================

剛剛在觀看「smplayer」的原始碼

然後執行下面指令,來對照著看

================================================================================

先開啟一個「Terminal」,執行下面指令,使用「smplayer」來播放「~/Videos/test.mp4」。


$ smplayer ~/Videos/test.mp4



接著在另一個「Terminal」執行下面指令


$ ps aux | grep mpv



顯示


user 13273 63.0 1.4 1885268 121832 pts/2 Sl+ 09:30 0:13 /usr/bin/mpv --no-config --no-quiet --terminal --no-msg-color --input-file=/dev/stdin --no-fs --hwdec=no --sub-auto=fuzzy --no-input-default-bindings --input-vo-keyboard=no --no-input-cursor --cursor-autohide=no --no-keepaspect --wid=65011731 --monitorpixelaspect=1 --osd-level=1 --osd-scale=1 --osd-bar-align-y=0.6 --sub-ass --embeddedfonts --sub-ass-line-spacing=0 --sub-scale=1 --sub-font=Arial --sub-color=#ffffffff --sub-shadow-color=#ff000000 --sub-border-color=#ff000000 --sub-border-size=0.75 --sub-shadow-offset=2.5 --sub-font-size=50 --sub-bold=no --sub-italic=no --sub-codepage=ISO-8859-1 --vid=1 --sub-pos=100 --volume=57 --cache=auto --start=82 --screenshot-template=cap_%F_%p_%02n --screenshot-format=jpg --screenshot-directory=/home/user/Pictures/smplayer_screenshots --audio-pitch-correction=yes --volume-max=110 --term-playing-msg=MPV_VERSION=${=mpv-version:} INFO_VIDEO_WIDTH=${=width} INFO_VIDEO_HEIGHT=${=height} INFO_VIDEO_ASPECT=${=video-aspect} INFO_VIDEO_FPS=${=container-fps:${=fps}} INFO_VIDEO_FORMAT=${=video-format} INFO_VIDEO_CODEC=${=video-codec} INFO_AUDIO_FORMAT=${=audio-codec-name} INFO_AUDIO_CODEC=${=audio-codec} INFO_AUDIO_RATE=${=audio-params/samplerate} INFO_AUDIO_NCH=${=audio-params/channel-count} INFO_LENGTH=${=duration:${=length}} INFO_DEMUXER=${=current-demuxer:${=demuxer}} INFO_SEEKABLE=${=seekable} INFO_TITLES=${=disc-titles} INFO_CHAPTERS=${=chapters} INFO_TRACKS_COUNT=${=track-list/count} METADATA_TITLE=${metadata/by-key/title:} METADATA_ARTIST=${metadata/by-key/artist:} METADATA_ALBUM=${metadata/by-key/album:} METADATA_GENRE=${metadata/by-key/genre:} METADATA_DATE=${metadata/by-key/date:} METADATA_TRACK=${metadata/by-key/track:} METADATA_COPYRIGHT=${metadata/by-key/copyright:} INFO_MEDIA_TITLE=${=media-title:} INFO_STREAM_PATH=${stream-path} --audio-client-name=SMPlayer --term-status-msg=STATUS: ${=time-pos} / ${=duration:${=length:0}} P: ${=pause} B: ${=paused-for-cache} I: ${=core-idle} VB: ${=video-bitrate:0} AB: ${=audio-bitrate:0} /home/user/Videos/test.mp4



上面這段,我之前有在「#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」,執行下面指令


mkfifo /tmp/mpv-fifo

mpv --input-file=/tmp/mpv-fifo --idle


接著開啟另一個「Terminal」,執行下面指令


echo 'loadfile https://www.youtube.com/watch?v=Lqe3MuCyh9o' > /tmp/mpv-fifo



稍等一下,就會看到「mpv」播放「影片」。

接著回到樓主原本提的需求,執行下面指令


echo 'seek 00:01:00 absolute' > /tmp/mpv-fifo



就可以下指令,控制「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


$ sudo apt-get install socat



先開啟一個「Terminal」,執行下面指令


mpv --input-ipc-server=/tmp/mpv-pipe --idle



接著開啟另一個「Terminal」,執行下面指令


echo '{"command": ["loadfile", "https://www.youtube.com/watch?v=Lqe3MuCyh9o"]}' | socat - /tmp/mpv-pipe



會收到


{"data":null,"error":"success"}



稍等一下,就會看到「mpv」播放「影片」。

接著回到樓主原本提的需求,執行下面指令


echo '{"command": ["seek", "00:01:00", "absolute"]}' | socat - /tmp/mpv-pipe



就可以下指令,控制「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

================================================================================

執行


mpv --input-cmdlist



顯示


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




================================================================================

執行


mpv -h



或是


mpv --help



顯示


Usage: mpv [options] [url|path/]filename

Basic options:
--start=<time> seek to given (percent, seconds, or hh:mm:ss) position
--no-audio do not play sound
--no-video do not play video
--fs fullscreen playback
--sub-file=<file> specify subtitle file to use
--playlist=<file> specify playlist file

--list-options list all mpv options
--h=<string> print options which contain the given string in their name



================================================================================

其他範例如下

執行


mpv --list-options



執行


mpv --h=input-file



執行


mpv --h=input-ipc-server



執行


mpv --h=idle



執行


mpv --h=list



執行


mpv --list-properties



執行


mpv --list-protocols



執行


mpv --list-protocols



執行


mpv --input-cmdlist



執行


mpv --input-keylist



執行


mpv --h=cache



執行


$ mpv --cache-secs=600 'https://www.youtube.com/watch?v=Lqe3MuCyh9o'



================================================================================

上面「方式一」,可以簡化成下面步驟

先開啟一個「Terminal」,執行下面指令


mkfifo /tmp/mpv-fifo

mpv --input-file=/tmp/mpv-fifo --cache-secs=600 'https://www.youtube.com/watch?v=Lqe3MuCyh9o'



接著執行下面指令


echo 'seek 00:01:00 absolute' > /tmp/mpv-fifo



就可以下指令,控制「mpv」從「00:01:00」開始播放影片。

================================================================================

以上提供參考,

報告完畢


2019/3/13 13:08
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.