Open grenzionky opened 4 years ago
There was a bug that was recently fixed which was causing problems with large buffers, but most distributions have an older version of xclip in their repositories if you're installing from a package manager.
Try installing from source. I just tested this on a Manjaro live cd and it worked fine.
git clone https://github.com/astrand/xclip.git
cd ./xclip
autconf
./configure
make
sudo make install
'xclip -version' should show version 0.13.
I just tested the most recent commit using a 3.1 GB .mp4 file and found that it worked fine.
xclip -selection clipboard -i /mnt/vraid/shared/20170112_153841.mp4
xclip -selection clipboard -o > ./test.mp4
md5sum -b /mnt/vraid/shared/20170112_153841.mp4 ./test.mp4 13b3685c5ea264443060bb68a390da0d /mnt/vraid/shared/20170112_153841.mp4 13b3685c5ea264443060bb68a390da0d ./test.mp4
https://streamable.com/slha3 do you know what this error is?
https://streamable.com/lyjdl i have version 0.13 and it still doesnt work…
That error means there was a problem when xclip tried to send the data to a dummy window that it creates to hold the selection data.
However, I'm unable to reproduce the same error in a virtual machine using the following:
xclip 0.13 Yakuake Version 3.0.5+ AwesomeWM v 4.3 Xorg X 1.20.5 Linux 5.2.21
Are you using proprietary video drivers by chance? Maybe try looking in /var/log/Xorg.0.log for any error messages.
Can you try running with the '-verbose' option?
/var/log/* doesnt have anything related XA_CLIPBOARD or xclip anywhere (except in the pacman log, from when i installed xclip), neither are there any new entries since i booted the system.
thanks for troubleshooting for me btw. its really appreciated
Hmm, that's interesting. It looks like in the first instance you ran while supplying it the mime-type, that it's loaded it up and is waiting for a selection request as it should. However, the second time, it says it's loading it as UTF8 string, which is obviously incorrect. But in the first instance, "Waiting for another selection request" means that it's ready for something to request and transfer from the selection.
Try the first command you ran again and then in another terminal (while the first instance of xclip you launched is still running) try running xclip with the -o option but supplying it the same mime-type with '-t' and 'file', but redirect the output into a file 'test.mp4', so...
xclip -verbose -t "$(file -b --mime-type blockattacktrailer.mp4)" -o > ./test.mp4
Check the output of both terminal windows for any error messages, and check if the video copied into test.mp4 correctly.
It's strange because on my setup and using the .mp4 file I tested, without supplying the mime-type, it also treats it as a UTF8 string, but for me it doesn't fail or produce that X error. You'll have to run the xclip command to request that selection and redirect the output out to test.mp4 to see if it's actually working correctly though. Hopefully with both instances in verbose mode, if it doesn't work, it will reveal some more clues about why.
No problem, glad to help. Would you be opposed to uploading the video you're working with? It might be useful to test with the actual data that's giving you issues.
this is the vid: https://youtu.be/6mlaqMMOwiU im just using it as a test video. i tried copying other videos, but i get the same error for them too…
$ xclip -verbose -selection clipboard -t "$(file -b --mime-type blockattacktrailer.mp4)" -i ~/videos/blockattacktrailer.mp4
Connected to X server.
Using selection: XA_CLIPBOARD
Using video/mp4.
Reading /home/nitsi/videos/blockattacktrailer.mp4...
Waiting for selection requests, Control-C to quit
Waiting for selection request number 1
Waiting for selection request number 2
$ xclip -verbose -t "$(file -b --mime-type blockattacktrailer.mp4)" -o > ./test.mp4
Connected to X server.
Using video/mp4.
Error: target video/mp4 not available
$ ls -lh test.mp4
-rw-r--r-- 1 nitsi nitsi 0 11月 5 15:41 test.mp4
Sorry for the late response.
That error is indicating that the XConvertSelection call at line 158 in xclib.c failed. Without being able to reproduce the bug though, I can't really determine why, nor am I reasonably able to attribute it to xclip itself. Since you're also getting that BadWindow error, I'm still suspecting there is something wrong when it calls X, rather than it being a problem with xclip.
There are also other layers to consider between xclip and X. You might want to try it in a different window manager and terminal emulator. xclip has to create a dummy window to send the selection data to, so if there is a problem with that window being created then it can throw off the whole works. I've never really heard much about AwesomeWM, but know Yakuake has kind of special functionality since it pulls-down when you press F12. If you try on something like XFCE with its terminal emulator and don't have a problem it could narrow down the cause.
I know none of this really solves your problem or how you want to use it, but at this point it definitely seems like the issue is somewhere else in your system configuration and not with xclip itself, but if you can try with different window managers and terminal emulators you can at least rule those out. I'd also still try grep'ing your /var/log/Xorg.0.log file for 'EE' and 'WW' just to make sure there's no errors and warnings pertaining to your xorg configuration. It's kind of a long shot, but if there is a warning/error it could indicate there's a larger problem with your X server configuration that might be contributing to this problem.
Have you by chance tried to use the primary selection? I'm guessing you wanted to use the clipboard selection for a reason, but it might be useful to try using the primary selection as a troubleshooting measure.
after testing, in kde, xfce, and awesome, and many terminal emulators, only doing -t MIME
and -selection primary/clipboard
made it work. however, it only pastes when i use xclip -selection «same as -i» -o > file.mp4
, but this doesnt accomplish anything, since doing cp
does the same thing…
When i do -selection primary
/-selection clipboard
, using the scroll wheel click/pressing ctrl+v doesnt paste the video in a place that accepts videos as input, like file managers and telegram.
middle clicking/ctrl+v into file managers/telegram doesnt make xclip say Waiting for selection request number X
, so idk what the issue is. middle clicking/ctrl+v in a terminal window does make Waiting for selection request number
update by a couple numbers, but nothing gets pasted.
i reinstalled xorg and xorg drivers, but it still does the same thing.
heres the warnings and errors.
~|⇒ grep "(EE)" /var/log/Xorg.0.log
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[ 6.080] (EE) Failed to open authorization file "/var/run/sddm/{504b3ae2-91ee-492b-ae42-a559187ce11e}": No such file or directory
~|⇒ grep "(WW)" /var/log/Xorg.0.log
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[ 5.104] (WW) The directory "/usr/share/fonts/Type1" does not exist.
[ 5.125] (WW) Open ACPI failed (/var/run/acpid.socket) (No such file or directory)
[ 5.153] (WW) Falling back to old probe method for modesetting
[ 5.153] (WW) Falling back to old probe method for fbdev
heres the output of xclip when i dont specify the mime type. this happens regarldless of WM/terminal/shell
~|⇒ xclip -verbose -selection clipboard -i videos/blockattacktrailer.mp4
Connected to X server.
Using selection: XA_CLIPBOARD
Using UTF8_STRING.
Reading videos/blockattacktrailer.mp4...
Waiting for selection requests, Control-C to quit
Waiting for selection request number 1
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 18 (X_ChangeProperty)
Resource id in failed request: 0x1a00005
Serial number of failed request: 24
Current serial number in output stream: 24
~|⇒ xclip -verbose -selection primary -i videos/blockattacktrailer.mp4
Connected to X server.
Using selection: XA_PRIMARY
Using UTF8_STRING.
Reading videos/blockattacktrailer.mp4...
Waiting for selection requests, Control-C to quit
Waiting for selection request number 1
Waiting for selection request number 2
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 18 (X_ChangeProperty)
Resource id in failed request: 0x3000038
Serial number of failed request: 33
Current serial number in output stream: 33
text and images work just fine, so why are videos any different?
I know this is an old issue but has there been any solution to this? Tying to achieve the same functionality @grenzionky
I have recently fixed many issues and added an X error handler that should catch Bad Window. I also added a bunch more debugging, so, if nothing else, we'll be able to track down these problems more easily. My changes haven't been merged into the mainline yet, but I hope that they will be soon. If you're eager to try them out, you can get them from the hackerb9 branch. Let me know if this fixes the problem.
Hi,
I am not able to get videos in to the clipboard with hackerb9 branch. mp4s and webms were tried.
The size of the video is 492K, so it's relatively small.
ls -lah /home/brody/Videos/Clips/22-02-26-181550.webm
-rwxrwxr-x 1 brody brody 492K Feb 26 18:16 /home/brody/Videos/Clips/22-02-26-181550.webm
Here is the output asked for from https://github.com/astrand/xclip/issues/74#issuecomment-549602299 -- but with -debug instead of only verbose. Not sure if it'll help.
/home/brody/Projects/git/xclip/xclip -debug -selection clipboard -t video/webm -i /home/brody/Videos/Clips/22-02-26-181550.webm
xclip: debug: Debugging enabled.
Connected to X server.
Using selection: XA_CLIPBOARD
Using target: video/webm
xclip: debug: Our window is window id 0x4a00001
Reading /home/brody/Videos/Clips/22-02-26-181550.webm...
xclip: debug: Increased buffersize to 32
xclip: debug: Increased buffersize to 64
xclip: debug: Increased buffersize to 128
xclip: debug: Increased buffersize to 256
xclip: debug: Increased buffersize to 512
xclip: debug: Increased buffersize to 1024
xclip: debug: Increased buffersize to 2048
xclip: debug: Increased buffersize to 4096
xclip: debug: Increased buffersize to 8192
xclip: debug: Increased buffersize to 16384
xclip: debug: Increased buffersize to 32768
xclip: debug: Increased buffersize to 65536
xclip: debug: Increased buffersize to 131072
xclip: debug: Increased buffersize to 262144
xclip: debug: Increased buffersize to 524288
Waiting for selection requests, Control-C to quit
xclip: debug: Received SelectionRequest event
+ Creating new requestor 1600116-GDK_SELECTION for 'Caja' (0x1600116)
xclip: debug: event was sent by 'Caja' (0x1600116)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 1600116-GDK_SELECTION for 'Caja' (0x1600116)
________
Waiting for selection request number 2
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6a00003-GDK_SELECTION for 'Terminal' (0x6a00003)
xclip: debug: event was sent by 'Terminal' (0x6a00003)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 6a00003-GDK_SELECTION for 'Terminal' (0x6a00003)
________
Waiting for selection request number 3
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6a0b041-GDK_SELECTION for 'Terminal' (0x6a0b041)
xclip: debug: event was sent by 'Terminal' (0x6a0b041)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 6a0b041-GDK_SELECTION for 'Terminal' (0x6a0b041)
________
Waiting for selection request number 4
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6400001-XCLIP_OUT for window id 0x6400001
xclip: debug: event was sent by window id 0x6400001
xclib: debug: XCIN_NONE: target: UTF8_STRING.
xclib: debug: XCIN_NONE: Sending data all at once (503681 bytes).
- Deleting requestor 6400001-XCLIP_OUT for window id 0x6400001
________
Waiting for selection request number 5
^C
Here is the debug output for the paste-side of the xclip.
xclip -debug -selection clipboard -o > test.webm
xclip: debug: Debugging enabled.
Connected to X server.
Using selection: XA_CLIPBOARD
Using target: UTF8_STRING.
xclip: debug: Our window is window id 0x6400001
Current owner of CLIPBOARD is window id 0x4a00001.
xclib: debug: XCOUT_NONE: Requesting XConvertSelection(Display = :0.0, Selection = CLIPBOARD, Target = UTF8_STRING, Property = XCLIP_OUT, Window = window id 0x6400001, Time = 0)
xclib: debug: XCLIB_XCOUT_SENTCONVSEL: ignoring PropertyNotify event.
xclib: debug: XCLIB_XCOUT_SENTCONVSEL: Requesting XGetWindowProperty(Display = :0.0, Window = window id 0x6400001, Property = XCLIP_OUT, Offset = 0, Length = 503681, Delete = False, Req_type = AnyPropertyType...)
Received 503681 bytes of data.
Type is video/webm.
If I do not specify the mime type, the paste still works through CLI:
/home/brody/Projects/git/xclip/xclip -debug -selection clipboard -i /home/brody/Videos/Clips/22-02-26-181550.webm
xclip: debug: Debugging enabled.
Connected to X server.
Using selection: XA_CLIPBOARD
Using target: UTF8_STRING.
xclip: debug: Our window is window id 0x4a00001
Reading /home/brody/Videos/Clips/22-02-26-181550.webm...
xclip: debug: Increased buffersize to 32
xclip: debug: Increased buffersize to 64
xclip: debug: Increased buffersize to 128
xclip: debug: Increased buffersize to 256
xclip: debug: Increased buffersize to 512
xclip: debug: Increased buffersize to 1024
xclip: debug: Increased buffersize to 2048
xclip: debug: Increased buffersize to 4096
xclip: debug: Increased buffersize to 8192
xclip: debug: Increased buffersize to 16384
xclip: debug: Increased buffersize to 32768
xclip: debug: Increased buffersize to 65536
xclip: debug: Increased buffersize to 131072
xclip: debug: Increased buffersize to 262144
xclip: debug: Increased buffersize to 524288
Waiting for selection requests, Control-C to quit
xclip: debug: Received SelectionRequest event
+ Creating new requestor 1600116-GDK_SELECTION for 'Caja' (0x1600116)
xclip: debug: event was sent by 'Caja' (0x1600116)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 1600116-GDK_SELECTION for 'Caja' (0x1600116)
________
Waiting for selection request number 2
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6a00003-GDK_SELECTION for 'Terminal' (0x6a00003)
xclip: debug: event was sent by 'Terminal' (0x6a00003)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 6a00003-GDK_SELECTION for 'Terminal' (0x6a00003)
________
Waiting for selection request number 3
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6a0c49a-GDK_SELECTION for 'Terminal' (0x6a0c49a)
xclip: debug: event was sent by 'Terminal' (0x6a0c49a)
xclib: debug: XCIN_NONE: target: TARGETS.
xclib: debug: XCIN_NONE:sending list of TARGETS.
- Deleting requestor 6a0c49a-GDK_SELECTION for 'Terminal' (0x6a0c49a)
________
Waiting for selection request number 4
xclip: debug: Received SelectionRequest event
+ Creating new requestor 6400001-XCLIP_OUT for window id 0x6400001
xclip: debug: event was sent by window id 0x6400001
xclib: debug: XCIN_NONE: target: UTF8_STRING.
xclib: debug: XCIN_NONE: Sending data all at once (503681 bytes).
- Deleting requestor 6400001-XCLIP_OUT for window id 0x6400001
________
Waiting for selection request number 5
^C
Paste:
xclip -debug -selection clipboard -o > test.webm
xclip: debug: Debugging enabled.
Connected to X server.
Using selection: XA_CLIPBOARD
Using target: UTF8_STRING.
xclip: debug: Our window is window id 0x6400001
Current owner of CLIPBOARD is window id 0x4a00001.
xclib: debug: XCOUT_NONE: Requesting XConvertSelection(Display = :0.0, Selection = CLIPBOARD, Target = UTF8_STRING, Property = XCLIP_OUT, Window = window id 0x6400001, Time = 0)
xclib: debug: XCLIB_XCOUT_SENTCONVSEL: ignoring PropertyNotify event.
xclib: debug: XCLIB_XCOUT_SENTCONVSEL: Requesting XGetWindowProperty(Display = :0.0, Window = window id 0x6400001, Property = XCLIP_OUT, Offset = 0, Length = 503681, Delete = False, Req_type = AnyPropertyType...)
Received 503681 bytes of data.
Type is UTF8_STRING.
nice
any workaround for this? I can't copy videos with xclip
Ctrl + V does nothing in Telegram Desktop, Thunar:
f=~/test.mp4; xclip -selection clipboard -t "$(file -b --mime-type $f)" -i $f
when I do xclip -selection clipboard -o
after this, I get some unknown symbols.
If I do something like xclip -selection clipboard -o > foo.mp4
, then I'll get copy of the video, playable with mpv.
but this works excellent:
f=~/test.png; xclip -selection clipboard -t "$(file -b --mime-type $f) -i $f
also I can copy video in Thunar and I can paste it into any application (Telegram Desktop, for example) with no problems
when I do xclip -selection clipboard -o
after this, I'll get just path of the file.
If it can help, I heard that Thunar is using file://
URI for copying files.
I couldn't find any info about how Thunar copying files.
(sorry for my english, I'm trying to stop using translator everytime)
@goosegit11
I had the same issue while working on a script that allows me to easily region capture screenshots and short video clips with ffmpeg's x11grab similar to how ShareX works on windows. I was easily able to copy images with xclip and send them via Telegram, but no matter what I did Telegram would not accept my video clips. I could still paste the videos to my file manager without issues. I knew that there had to be a way to make it work as if I copied the same mp4 from the file manager I could paste it to Telegram without any issues, so I kept searching the internet for days not finding anything. I finally figured it out after reading more about mime types and the x11 clipboard.
Turns out Telegram just does not support pasting video files from x11 clipboard. Most file managers do not seem to copy videos to clipboard but only the file names with mime type text/uri-list
With this information the solution becomes very simple:
echo "file:///filename.mp4" | xclip -sel clip -t text/uri-list -i
I hope that if someone else is having the same issue they are able to find this post before spending days on finding a solution like I had to.
same issue as @Goosegit11 here
@mak3e Whoa, I just saw it now.
Since I couldn't find a solution to the problem despite my best efforts, I replaced xclip with cb. Good software. Cool that you were able to find a solution for xclip, hope my comment here helped you with that.
Are you planning to publish your ffmpeg script? I was just looking for something similar that can record short gifs for showcase purposes. SimpleScreenRecorder can do this, but the developer didn't imply a CLI interface. I tried to adapt it to CLI with wrappers and python scripts, but it's a horrible dirty hack.
@halvabner Make posted a solution just above your comment, have you tried it?
@Goosegit11
I've since switched to Wayland and last time I checked all options for region video capture under Wayland were so impractical to use or implement with code that I just gave up for now.
I don't think I have the code anymore but replicating my solution for X should be only a few lines of code. Just check ffmpeg's docs for x11grab module. It has built in support for region selection. I remember having issues with finding optimal parameters for video encoding and keeping audio in sync so those might require a bit of experimentation.
The problem with something like slop is that ffmpeg will record just coordinates, cause that's what slop gives.
For example:
#!/bin/bash
slop=$(slop -f "%x %y %w %h %g %i") || exit 1
read -r X Y W H G ID <<< $slop
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse ~/myfile.webm
If you move the window when recording, ffmpeg won't adapt
lol, i just independently discovered @mak3e 's solution and only now i realize he had already posted the solution
but yes, if it's an absolute path /home/user/filename.mp4
you basically need
echo -n 'file:///home/user/filename.mp4' | xclip -sel clip -t text/uri-list -i
works with discord/telegram, works with mp3's, images, almost anything
no matter what i tried, copying videos to the clipboard didnt work.
am i doing something wrong? or is this a bug?
im using