summaryrefslogtreecommitdiffstats
path: root/player/screenshot.c
Commit message (Collapse)AuthorAgeFilesLines
* image_writer: fix TOCTOU in screenshot filename generationnanahi2024-03-191-4/+5
| | | | | | | | | | | | | | | | The screenshot command is documented to not overwrite existing files. However, there is a race window between the filename is generated with gen_fname and when the file is open to write. Specifically, the convert_image function in this window can be very time consuming depending on video and screenshot image format and size. This results in existing file being overwritten because the file writing functions don't check for the existance of file. Fix this be opening the file in exclusive mode. Add overwrite parameter to write_image for other operations that are documented to overwrite existing files, like screenshot-to-file. Note that for write_avif, checking existance is used instead because avio_open does not support exclusive open mode.
* screenshot: remove artificial limit on the number of screenshots takennanahi2023-12-281-1/+1
| | | | | | This allows taking more than 99999 screenshots in a single session, and also for the case when a sequence of 99999 screenshots already exists on the filesystem.
* mp_thread: add win32 implementationKacper Michajłow2023-11-051-1/+0
|
* options: rename --screenshot-directory to --screenshot-dirDudemanguy2023-10-251-1/+1
| | | | | Less characters is better? Other options use -dir for directory so consistency I guess.
* win32/pthread: define _POSIX_TIMERS to notify they are not supportedKacper Michajłow2023-09-291-0/+1
|
* screenshot: support crop with --screenshot-swKacper Michajłow2023-09-091-0/+13
|
* screenshot: implement screenshot-window in sw for most VOsDudemanguy2023-07-211-6/+29
| | | | | | mpv already has a bunch of software scaling utils. Instead of forcing every VO to implement this, we can just grab the frame and scale it in software in one central place. Fixes #11968.
* screenshot: clarify software screenshot logicDudemanguy2023-07-211-15/+20
| | | | | | | | We should always be trying hardware screenshots (VOCTRL_SCREENSHOT and VOCTRL_SCREENSHOT_WIN) before software ones. Rearrange all the logic here to hopefully make this clearer. The mode is passed to add_osd (renamed since it will also be used to add the osd) which will be used more in the next commit.
* image_writer: move tag_csp check into image_writer_flexible_csp()sfan52023-07-191-1/+1
| | | | | | | This ensures the sRGB fallback to happen in all situations involving the image writer code, notably --screenshot-sw. fixes: cbbe2e52210d9885a0897e9c7833267a60456c56
* player/screenshot: add "screenshot" loggercloud116652023-07-011-1/+4
|
* player/screenshot: avoid non-sRGB spaces with --screenshot-tag-csp=noLeo Izen2023-04-101-1/+1
| | | | | | If --screenshot-tag-csp=no, then there won't be any color tags in the output space, so PNG and JXL screenshots should be written as sRGB rather than the native space of the input video.
* player/screenshot: add filename return fieldcloud116652023-03-251-1/+7
| | | | DOCS/input: add screenshot return value description
* screenshot: fix segfault when taking a screenshot without videoChristoph Heinrich2023-03-071-25/+29
| | | | Also a style change to exit early when nothing can be done anymore.
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-201-2/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* player/screenshot: pass on ability to output native CSPNiklas Haas2023-02-131-2/+5
| | | | Fixes: #10988
* screenshot: explicitly default VOCTRL_SCREENSHOT cspNiklas Haas2023-02-131-0/+1
| | | | | | | | | This allows the logic in `convert_image` to fast-path if the image params are equal. Without this check, the image params are basically never equal, because that path goes through `mp_image_params_guess_csp` while the `mp_image` itself does not. Force it here for consistency across VOs.
* screenshot: add --screenshot-sw optionwm42020-10-051-1/+2
| | | | | Probably worthless. As usual, the manpage dumps all the subtle differences due to implementation details on the user.
* screenshot: fix typo in commentwm42020-02-071-1/+1
| | | | | It was not meant to imply that screenshots are male. Female (and other) screenshots are also welcome to this project.
* player: make screenshot each-frame mode more accuratewm42020-02-071-1/+6
| | | | | | | | | | | | | | | | | | | | | | | Due to asynchronicity, we generally can't guarantee that a video frame matches up with other events such as playback time change exactly (since decoding, presentation, and property update all happen at different times). This is a complaint in the referenced bug report, where screenshot filenames in each-frame screenshot did not use the correct timestamp, and instead was lagging behind by 1 frame. But in this case, synchronicity was already pretty much forced with wait calls. The only problem was that the playback time was updated at a later time, which results in the observed 1 frame lag. Fix this by moving the place where the screenshot is triggered in this mode. Normal screenshots may still have the old problem. There is no effort made to guarantee the timestamps absolutely line up, same as with the OSD. (If you want a guarantee, you need to use a video filter, such as libavfilter's drawtext. These will obviously use the proper timestamp, instead of going through the somewhat asynchronous property etc. system in the player frontend.) Fixes: #7433
* screenshot, vo_image: use global swscale/zimg parameterswm42019-10-311-4/+13
| | | | | | | | | | Lots of dumb crap to do... something. Instead of adding yet another dumb helper, just use the main" sws_utils API in both callers. (Which, unfortunately, has been duplicated for glorious webp screenshots, despite the fact that webp is crap.) Good part: can enable zimg for screenshots (as far as needed). Bad part: uses "default" swscale parameters instead of HQ now.
* screenshot: move message showing to common codewm42019-09-191-46/+19
| | | | | | | | | | | | | | The screenshot command has this weird behavior that it shows messages both on terminal and OSD by default, but that a command prefix can be used to disable the OSD message. Move this mechanism to common code, and make this available to other commands too (although as of this commit only the screenshot commands use it). This gets rid of the weird screenshot_ctx.osd field too, which was sort of set on a command, and sometimes inconsistently restored after the command.
* image_writer: move convert_image() to player/screenshot.csfan52019-09-141-0/+37
|
* command: add a way to abort asynchronous commandswm42018-05-241-1/+1
| | | | | | | | | | | | Many asynchronous commands are potentially long running operations, such as loading something from network or running a foreign process. Obviously it shouldn't just be possible for them to freeze the player if they don't terminate as expected. Also, there will be situations where you want to explicitly stop some of those operations explicitly. So add an infrastructure for this. Commands have to support this explicitly. The next commit uses this to actually add support to a command.
* screenshot: report success to callerwm42018-05-241-3/+7
| | | | Matters only to API callers, but still nice to have.
* screenshot: change async behavior to be in line with new semanticswm42018-05-241-112/+67
| | | | | | | | | | | | | | | | | | | | | | Basically reimplement the async behavior on top of the async command code. With this, all screenshot commands are async, and the "async" prefix basically does nothing. The prefix now behaves exactly like with other commands that use spawn_thread. This also means using the prefix in the preset input.conf is pointless (without effect) and misleading, so remove that. The each_frame mode was actually particularly painful in making this change, since the player wants to block for it when writing a screenshot, and generally doesn't fit into the new infrastructure. It was still relatively easy to reimplement by copying the original command and then repeating it on each frame. The waiting is reentrant now, so move the call in video.c to a "safer" spot. One way to observe how the new semantics interact with everything is using the mpv repl script and sending a screenshot command through it. Without async flag, the script will freeze while writing the screenshot (while playback continues), while with async flag it continues.
* command: move screenshot command stubs to screenshot.cwm42018-05-241-5/+61
| | | | | | | | | | Commands are not a monolithic giant switch() statement anymore, but individual functions. There's no reason to have the command handlers themselves in command.c, with a weird under-defined API in between. (In the future, I'd like to split up command.c further, and when I do that, scrrenshot.c will probably gets its own mp_cmd_def[] array, and define the commands locally instead of exporting the raw handlers.)
* thread_pool: make it slightly less dumbwm42018-05-241-1/+1
| | | | | | | | | | | | The existing thread pool code is the most primitive thread pool possible. That's fine, but one annoying thing was that it used a static number of threads. Make it dynamic, so we don't need to "waste" idle threads. This tries to add threads as needed. If threads are idle for some time, destroy them again until a minimum number of threads is reached. Also change the license to ISC.
* vo_gpu: make screenshots use the GL rendererwm42018-02-111-7/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | Using the GL renderer for color conversion will make sure screenshots will use the same conversion as normal video rendering. It can do this for all types of screenshots. The logic when to write 16 bit PNGs changes. To approximate the old behavior, we decide by looking whether the source video format has more than 8 bits per component. We apply this logic even for window screenshots. Also, 16 bit PNGs now always include an unused alpha channel. The reason is that FFmpeg has RGB48 and RGBA64 formats, but no RGB064. RGB48 is 3 bytes and usually not supported by GPUs for rendering, so we have to use RGBA64, which forces an alpha channel. Will break for users who use --target-trc and similar options. I considered creating a new gl_video context, but it could double GPU memory use, so I didn't. This uses FBOs instead of glGetTexImage(), because that increases the chance it could work on GLES (e.g. ANGLE). Untested. No support for the Vulkan and D3D11 backends yet. Fixes #5498. Also fixes #5240, because the code for reading back is not used with the new code path.
* video: make decoder wrapper a filterwm42018-01-301-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Move dec_video.c to filters/f_decoder_wrapper.c. It essentially becomes a source filter. vd.h mostly disappears, because mp_filter takes care of the dataflow, but its remains are in struct mp_decoder_fns. One goal is to simplify dataflow by letting the filter framework handle it (or more accurately, using its conventions). One result is that the decode calls disappear from video.c, because we simply connect the decoder wrapper and the filter chain with mp_pin_connect(). Another goal is to eventually remove the code duplication between the audio and video paths for this. This commit prepares for this by trying to make f_decoder_wrapper.c extensible, so it can be used for audio as well later. Decoder framedropping changes a bit. It doesn't seem to be worse than before, and it's an obscure feature, so I'm content with its new state. Some special code that was apparently meant to avoid dropping too many frames in a row is removed, though. I'm not sure how the source code tree should be organized. For one, video/decode/vd_lavc.c is the only file in its directory, which is a bit annoying.
* screenshot: create directories from templateNicolas F2017-11-021-0/+5
| | | | | screenshot-template could be set to e.g. "%F/%04n", so we want to make sure that the path generated from the template actually exists.
* video: remove special path for hwdec screenshotswm42017-10-161-6/+0
| | | | | | | This was phased out, and was used only by vdpau by now. Drop the mechanism and the vdpau special code, which means screenshots won't include the vf_vdpaupp processing anymore. (I don't care enough about vdpau, it's on its way out.)
* screenshot: cleanup: use normal MSGL_ defineswm42017-04-011-19/+9
| | | | Remove the weird custom thing.
* player: make screenshot commands honor the async flagwm42017-04-011-24/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | And also change input.conf to make all screenshots async. (Except the every-frame mode, which always uses synchronous mode and ignores the flag.) By default, the "screenshot" command is still asynchronous, because scripts etc. might depend on this behavior. This is only partially async. The code for determining the filename is still always run synchronously. Only encoding the screenshot and writing it to disk is asynchronous. We explicitly document the exact behavior as undefined, so it can be changed any time. Some of this is a bit messy, because I wanted to avoid duplicating the message display code between sync and async mode. In async mode, this is called from a worker thread, which is not safe because showing a message accesses the thread-unsafe OSD code. So the core has to be locked during this, which implies accessing the core and all that. So the code has weird locking calls, and we need to do core destruction in a more "controlled" manner (thus the outstanding_async field). (What I'd really want would be the OSD simply showing log messages instead.) This is pretty untested, so expect bugs. Fixes #4250.
* screenshot: change details of --screenshot-format handlingwm42017-03-181-2/+3
| | | | | | | | | | | | | | | | This is just a pointless refactor with the only goal of making image_writer_opts.format a number. The pointless part of it is that instead of using some sort of arbitrary ID (in place of a file extension string), we use a AV_CODEC_ID_. There was also some idea of falling back to the libavcodec MJPEG encoder if mpv was not linked against libjpeg, but this fails. libavcodec insist on having AV_PIX_FMT_YUVJ420P, which we pretend does not exist, and which we always map to AV_PIX_FMT_YUV420P (without the J indicating full range), so encoder init fails. This is pretty dumb, but whatever. The not-caring factor is raised by the fact that we don't know that we should convert to full range, because encoders have no proper way to signal this. (Be reminded that AV_PIX_FMT_YUVJ420P is deprecated.)
* screenshot: minor simplificationwm42017-03-181-7/+4
| | | | | | | | This also will set image=NULL, if the video frame is marked as hwaccel, and could not be copied to normal RAM. This will probably change the error message (due to screenshot_get() returning NULL, instead of making image conversion fail at a later point), but the behavior is the same anyway.
* cuda: use libavutil functions for copying hw surfaces to memorywm42017-01-121-6/+10
| | | | | | | | mp_image_hw_download() is a libavutil wrapper added in the previous commit. We drop our own code completely, as everything is provided by libavutil and our helper wrapper. This breaks the screenshot code, so that has to be adjusted as well.
* video: refactor how VO exports hwdec device handleswm42016-05-091-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | The main change is with video/hwdec.h. mp_hwdec_info is made opaque (and renamed to mp_hwdec_devices). Its accessors are mainly thread-safe (or documented where not), which makes the whole thing saner and cleaner. In particular, thread-safety rules become less subtle and more obvious. The new internal API makes it easier to support multiple OpenGL interop backends. (Although this is not done yet, and it's not clear whether it ever will.) This also removes all the API-specific fields from mp_hwdec_ctx and replaces them with a "ctx" field. For d3d in particular, we drop the mp_d3d_ctx struct completely, and pass the interfaces directly. Remove the emulation checks from vaapi.c and vdpau.c; they are pointless, and the checks that matter are done on the VO layer. The d3d hardware decoders might slightly change behavior: dxva2-copy will not use the VO device anymore if the VO supports proper interop. This pretty much assumes that any in such cases the VO will not use any form of exclusive mode, which makes using the VO device in copy mode unnecessary. This is a big refactor. Some things may be untested and could be broken.
* player: fix use-after-free with --screenshot-directorywm42016-04-141-1/+2
| | | | Probably fixes #3049.
* Relicense some non-MPlayer source files to LGPL 2.1 or laterwm42016-01-191-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This covers source files which were added in mplayer2 and mpv times only, and where all code is covered by LGPL relicensing agreements. There are probably more files to which this applies, but I'm being conservative here. A file named ao_sdl.c exists in MPlayer too, but the mpv one is a complete rewrite, and was added some time after the original ao_sdl.c was removed. The same applies to vo_sdl.c, for which the SDL2 API is radically different in addition (MPlayer supports SDL 1.2 only). common.c contains only code written by me. But common.h is a strange case: although it originally was named mp_common.h and exists in MPlayer too, by now it contains only definitions written by uau and me. The exceptions are the CONTROL_ defines - thus not changing the license of common.h yet. codec_tags.c contained once large tables generated from MPlayer's codecs.conf, but all of these tables were removed. From demux_playlist.c I'm removing a code fragment from someone who was not asked; this probably could be done later (see commit 15dccc37). misc.c is a bit complicated to reason about (it was split off mplayer.c and thus contains random functions out of this file), but actually all functions have been added post-MPlayer. Except get_relative_time(), which was written by uau, but looks similar to 3 different versions of something similar in each of the Unix/win32/OSX timer source files. I'm not sure what that means in regards to copyright, so I've just moved it into another still-GPL source file for now. screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but they're all gone.
* player: refactor: eliminate MPContext.d_videowm42016-01-171-2/+2
| | | | | | | | | | | | | | Eventually we want the VO be driven by a A->V filter, so a decoder doesn't even have to exist. Some features definitely require a decoder though (like reporting the decoder in use, hardware decoding, etc.), so for each thing which accessed d_video, it has to be redecided if and how it can access decoder state. At least the "framedrop" property slightly changes semantics: you can now always set this property, even if no video is active. Some untested changes in this commit, but our bio-based distributed test suite has to take care of this.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* video: switch from using display aspect to sample aspectwm42015-12-191-8/+1
| | | | | | | | | | | | | | | | MPlayer traditionally always used the display aspect ratio, e.g. 16:9, while FFmpeg uses the sample (aka pixel) aspect ratio. Both have a bunch of advantages and disadvantages. Actually, it seems using sample aspect ratio is generally nicer. The main reason for the change is making mpv closer to how FFmpeg works in order to make life easier. It's also nice that everything uses integer fractions instead of floats now (except --video-aspect option/property). Note that there is at least 1 user-visible change: vf_dsize now does not set the display size, only the display aspect ratio. This is because the image_params d_w/d_h fields did not just set the display aspect, but also the size (except in encoding mode).
* screenshot: avoid confusing template error message with no fileKevin Mitchell2015-09-021-9/+11
| | | | | | | Previously, with mpv --force-window=yes --idle=yes --screenshot-template="%f", mpv would display an error saying that the template was incorrect, which it isn't, there's just no file to put in the format. In this case, just use the string "NO_FILE".
* path: make mp_path_join accept normal C stringswm42015-05-091-1/+1
| | | | | Instead of bstr. Most callers of this function do not need bstr. The bstr version of this function is now mp_path_join_bstr().
* options: fix typo in variable namewm42015-05-031-1/+1
|
* screenshots: create screenshot dirwm42015-05-021-0/+2
| | | | Minor user convenience.
* screenshots: add --screenshot-directory optionwm42015-05-011-0/+8
| | | | | The plan is to use this to change the screenshot default location in pseudo-gui mode.
* client API: add a screenshot_raw commandwm42015-04-201-0/+10
| | | | | | | | | Requested. The wild code for setting up the mpv_node probably deserves to be cleaned up later. Fixes #1800.
* vf_screenshot: remove this filterwm42015-04-161-6/+1
| | | | | | It's entirely useless, especially now that vo.c handles screenshots in a generic way, and requires no special VO support. There are some potential weird use-cases, but actually I've never seen it being used.
* command: let screenshot_to_file command overwrite fileswm42015-04-161-5/+0
| | | | | | | The old behavior does not make too much sense after all. If you don't want to file to be overwritten, the user can check this manually. This is a change in behavior - let's hope nobody actually relied on it.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* screenshot: use GPU readback only for hardware decoded imageswm42015-04-071-1/+1
| | | | | | Avoids a confusing message printed by the vdpau code when taking a screenshot while using software decoding (because obviously GPU readback won't work on normal in-memory video frames).
* player: fix crash when taking screenshots in idle modewm42015-03-111-0/+2
| | | | | | | | | | mpctx->filename is obviously not set if no file is playing. When this code was written, it probably couldn't happen, because the normal screenshot path fails much earlier in idle mode. But you can still take screenshots in "full window" mode, and recently the screenshot code was changed to use the "full window" mode if the normal path does not work.
* options: list correct default value for --screenshot-templatewm42015-01-261-1/+1
| | | | | | Make the default value part of the option metadata, instead of doing this in the screenshot code. Makes more sense with --list-options and the command.c option metadata properties.
*