mpvz icon indicating copy to clipboard operation
mpvz copied to clipboard

Video thumbnails on another window

Open varlesh opened this issue 4 years ago • 8 comments

Sometime player show thumbnails on mpv window Screenshot_20210817_062407

log:

qrc:/qml/MpvPlayer.qml:499:3: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
qrc:/qml/MpvPlayer.qml:473:4: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
qrc:/qml/VolumeSlider.qml:20:2: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
qrc:/qml/SeekbarSlider.qml:18:2: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
qrc:/qml/SeekbarSlider.qml:150:6: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
qrc:/qml/MpvPlayer.qml:40:31: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
Model size of -10 is less than 0
qml: onFileStarted
 (+) Video --vid=1 (*) (h264 640x360 30.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 44100Hz)
Using hardware decoding (nvdec-copy).
AO: [pulse] 44100Hz stereo 2ch float
VO: [libmpv] 640x360 nv12
qml: onFileLoaded
qml: filePath /home/alex/video/Garfield Kart Furious Racing/video2.mp4
qml: getDirPath file:///home/alex/video/Garfield Kart Furious Racing/
qml: basename video2.mp4
qml: folderModel.count 2

libmpv 0.32 mpvz from git

varlesh avatar Aug 17 '21 02:08 varlesh

video: Peek 2021-08-17 06-44

varlesh avatar Aug 17 '21 02:08 varlesh

I've been trying to figure out this race condition for a while now. I've tried removing hwdec, and using bomi's launch parameters. I'm doing something incorrectly.

Zren avatar Aug 17 '21 21:08 Zren

Hmm, I'm gonna test removing the Loader in SeekbarSlider.qml again.

The most annoying part of this bug is that I can't quickly reproduce it. The only indication I think I worked out was that the thumbnail mpv instance initialized before the video mpv instance.

You'll need to comment out this in mpvthumbnail.cpp:

	setOption("really-quiet", "yes"); // No stdout

Zren avatar Aug 17 '21 21:08 Zren

Try with this file: video.zip

varlesh avatar Aug 19 '21 05:08 varlesh

Hmmm, it's not the video itself, otherwise opening up the same file several times would reproduce the bug every time.

I think I've figured out how to reproduce it 50% of the time though.

In MpvPlayer.qml I force overlayControls.showOverlay to always be true

	Item {
		id: overlayControls
		anchors.fill: parent
		// readonly property bool showOverlay: headerBar.isHovered || controlBar.containsMouse || sidebar.containsMouse || hideCursorTimeout.running
		readonly property bool showOverlay: true
		readonly property bool isVisible: opacity > 0

Then in SeekbarSlider.qml I add

	Component.onCompleted: thumbnail.show(100)

I first tried thumbnail.show(0) but that did nothing the few times I ran it. show(1px) might be too close to the start of the episode? show(100px) seems far enough into the episode to trigger it. 100/1280 = 12.8% * 24min = 3min into the episode.

qml: onFileStarted
[file] This is a directory - adding to playlist.

Playing: /home/chris/Videos/Episode.mkv
qml: onFileEnded redirect
qml: onFileStarted
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
 (+) Subs  --sid=1 (*) (ass)
[ffmpeg] AVHWDeviceContext: Cannot load libcuda.so.1
[ffmpeg] AVHWDeviceContext: Could not dynamically load CUDA
AO: [pulse] 48000Hz stereo 2ch float
VO: [libmpv] 1280x720 yuv420p10
qml: onFileLoaded
qml: filePath /home/chris/Videos/Episode.mkv
qml: getDirPath file:///home/chris/Videos/
qml: basename Episode.mkv
qml: folderModel.count 2
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)
     Audio --aid=1 (*) (aac 2ch 48000Hz)
     Subs  --sid=1 (*) (ass)
Cannot load libcuda.so.1
VO: [gpu] 1280x720 yuv420p10

Since the mpv instance with just video is printed 2nd, my theory of the thumbnail loading first probably isn't the issue.

It is a race condition, but maybe the issue is that the window hasn't been created by the time the thumbnail mpv instance has been created? Edit: Window.window exists and Window.window.visible = true before show(100) is called. So it's not the window.

Zren avatar Aug 19 '21 22:08 Zren

I've managed to add some property change stdout logs which I shoulda added a while ago.

Here's what it looks like when the thumbnail is shown properly:

qml: SeekbarSlider Window.window MainWindow_QMLTYPE_146(0x56357acfb090, "mainWindow") true
qml: ThumbnailItem parent QQuickLoader(0x56357af86670)
qml: ThumbnailItem size 200 113
qml: ThumbnailItem Window.window MainWindow_QMLTYPE_146(0x56357acfb090, "mainWindow") true
qml: ThumbnailItem mpvObject MpvObject_QML_138(0x56357aed8a00, "mpvObject")
...
"mpvThumb" str  hwdec no
"mpvThumb" none hwdec-current 0
"mpvThumb" none hwdec-interop 0
"mpvThumb" none media-title 0
"mpvThumb" none path 0
"mpvThumb" none video-codec 0
"mpvThumb" none video-format 0
"mpvThumb" none video-params/pixelformat 0
"mpvThumb" none video-out-params/pixelformat 0
...
"mpvThumb" int  track-list/count 3
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)
     Audio --aid=1 (*) (aac 2ch 48000Hz)
     Subs  --sid=1 (*) (ass)
"mpvThumb" bool paused-for-cache false
"mpvThumb" bool seekable true
...
"mpvThumb" int  vo-delayed-frame-count 0
"mpvThumb" int  vid 1
"mpvThumb" doub container-fps 23.976
"mpvThumb" doub demuxer-cache-duration 0
"mpvThumb" doub time-pos 644
"mpvThumb" str  file-format mkv
...
"mpvThumb" str  hwdec-current no
"mpvThumb" str  video-codec h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
"mpvThumb" str  video-format h264
VO: [libmpv] 1280x720 yuv420p10

I've noticed that with thumbnail.show(1) the VO: [gpu] is printed before hwdec-current no and video-params/pixelformat yuv420p10.

VO: [gpu] 1280x720 yuv420p10
...
"mpvThumb" str  hwdec-current no
"mpvThumb" str  video-codec h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
"mpvThumb" str  video-format h264
"mpvThumb" str  video-params/pixelformat yuv420p10
"mpvThumb" str  video-out-params/pixelformat yuv420p10

Thumbnail in another window logs:

"mpvObject" int  vid 1
"mpvObject" int  aid 1
"mpvObject" int  sid 1
"mpvObject" int  audio-params/channel-count 2
"mpvObject" int  audio-params/samplerate 48000
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)
     Audio --aid=1 (*) (aac 2ch 48000Hz)
     Subs  --sid=1 (*) (ass)
Cannot load libcuda.so.1
qml: folderModel.count 2
"mpvThumb" bool idle-active false
"mpvThumb" bool paused-for-cache false
"mpvThumb" bool seekable true
"mpvThumb" int  chapter -1
...
"mpvThumb" int  vo-delayed-frame-count 0
"mpvThumb" int  vid 1
...
"mpvThumb" doub time-pos 0
"mpvThumb" str  filename video.mkv
"mpvThumb" str  file-format mkv
"mpvThumb" str  media-title video.mkv
"mpvThumb" str  path /home/chris/Videos/video.mkv
VO: [gpu] 1280x720 yuv420p10
"mpvObject" doub avsync 0.0279225
"mpvObject" doub estimated-vf-fps 23.976
"mpvObject" doub time-pos 0.083
"mpvObject" int  frame-drop-count 3
"mpvObject" doub avsync 0.010157
"mpvObject" doub estimated-vf-fps 23.976
"mpvObject" doub time-pos 0.167
"mpvObject" doub avsync 2e-05
"mpvObject" doub estimated-vf-fps 23.976
"mpvObject" doub time-pos 0.209
"mpvObject" doub avsync 3.6e-05
"mpvObject" doub time-pos 0.25
"mpvThumb" int  dheight 720
"mpvThumb" int  dwidth 1280
"mpvThumb" doub estimated-vf-fps 23.976
"mpvThumb" doub video-params/aspect 1.77778
"mpvThumb" doub video-out-params/aspect 1.77778
"mpvThumb" doub current-window-scale 1
"mpvThumb" str  hwdec-current no
"mpvThumb" str  video-codec h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
"mpvThumb" str  video-format h264
"mpvThumb" str  video-params/pixelformat yuv420p10
"mpvThumb" str  video-out-params/pixelformat yuv420p10
"mpvThumb" none estimated-vf-fps 0
"mpvThumb" doub time-pos 6
"mpvThumb" int  chapter 0

I'm definitely doing something too soon. I just realized that I also added an artificial 50ms delay to load the video in the larger mpv instance. If I get rid of that artificial delay, we get another gpu drawn window.

So I'm calling loadFile("video.mkv") too soon.

Zren avatar Aug 24 '21 05:08 Zren

I've used a lot of your code in another project of mine and can confirm that loading the file 50ms after the mpvobject component is loaded will make sure that the video or thumbnail isn't loaded in a new window. I sometimes got the video itself, not just the thumbnail, in a new window. But, perhaps somewhere in the c++ code there is something happening too soon.

ChrisCochrun avatar Feb 17 '22 16:02 ChrisCochrun

You're starting playback before the renderer is ready so mpv creates it's own window. You might be interested in https://invent.kde.org/libraries/mpvqt

Here's a patch to fix this

diff --git a/src/mpvobject.cpp b/src/mpvobject.cpp
index b39c267..da839fd 100644
--- a/src/mpvobject.cpp
+++ b/src/mpvobject.cpp
@@ -76,6 +76,7 @@ MpvRenderer::MpvRenderer(const MpvObject *obj)
 		throw std::runtime_error("failed to initialize mpv GL context");
 
 	mpv_render_context_set_update_callback(mpv_gl, MpvObject::on_update, (void *)obj);
+	emit obj->ready();
 }
 
 MpvRenderer::~MpvRenderer() {
diff --git a/src/mpvobject.h b/src/mpvobject.h
index ce03472..44321c2 100644
--- a/src/mpvobject.h
+++ b/src/mpvobject.h
@@ -124,6 +124,9 @@ public:
 	Q_INVOKABLE QString getChapterTitle(int chapterIndex) const { return getProperty(QString("chapter-list/%1/title").arg(chapterIndex)).toString(); }
 	Q_INVOKABLE double getChapterTime(int chapterIndex) const { return getProperty(QString("chapter-list/%1/time").arg(chapterIndex)).toDouble(); }
 
+signals:
+	void ready() const;
+
 public slots:
 	void command(const QVariant& params);
 	void commandAsync(const QVariant& params);
diff --git a/src/qml/ThumbnailItem.qml b/src/qml/ThumbnailItem.qml
index 4ea0836..95047d0 100644
--- a/src/qml/ThumbnailItem.qml
+++ b/src/qml/ThumbnailItem.qml
@@ -6,7 +6,7 @@ MpvThumbnail {
 	objectName: "mpvThumb"
 	anchors.fill: parent
 
-	Component.onCompleted: {
+	onReady: {
 		var thumbPosition = Math.floor(thumbnail.videoPosition) // 1 second interval
 		mpvThumb.setOption("start", '+'+thumbPosition)
 		if (mpvThumb.path != mpvObject.path) {
@@ -17,7 +17,7 @@ MpvThumbnail {
 	readonly property double steppedPos: Math.floor(thumbnail.videoPosition)
 	onSteppedPosChanged: {
 		if (mpvThumb.path != mpvObject.path) {
-			mpvThumb.loadFile(mpvObject.path)
+			// mpvThumb.loadFile(mpvObject.path)
 		}
 		visible = false
 		thumbSeekDebounce.restart()

g-fb avatar Dec 14 '23 09:12 g-fb