summaryrefslogtreecommitdiffstats
path: root/video/image_writer.c
Commit message (Collapse)AuthorAgeFilesLines
* image_writer: refactor screenshot write functionsnanahi2024-03-191-50/+24
| | | | | | | | | | | | When 3cb9119984b88b31a5b958b1b83efe8d1cf0b818 introduced AVIF screenshot support, FILE * in write functions were replaced by filenames. This resulted in unnecessary duplication of FILE * handling code and the usage of avio_open API made it hard to use exclusive open with it. To unify file handling, use avio_open_dyn_buf instead which writes to memory instead. This way FILE * can be used for the write functions and file handling code can be deduplicated. Since we now control the file opening, exclusive open can now be used for AVIF screenshots.
* image_writer: fix TOCTOU in screenshot filename generationnanahi2024-03-191-9/+24
| | | | | | | | | | | | | | | | 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.
* video/image_writer: attach MDVC metadata and CLLI metadataLeo Izen2024-03-191-8/+7
| | | | | | | | This commit allows image_writer to attach HDR metadata to AVFrames via the corresponding AVFrameSideData attachments, if present. It does this by calling pl_avframe_set_color, already used by mp_image_to_avframe. Signed-off-by: Leo Izen <leo.izen@gmail.com>
* image_writer: cleanup leftover files if image writing failsnanahi2024-02-251-2/+10
| | | | | This avoids leaving an empty/corrupt file if fopen succeeds but image writing fails afterwards.
* csputils: replace mp_chroma_location with pl_chroma_locationKacper Michajłow2024-01-221-2/+2
|
* csputils: replace mp_colorspace with pl_color_spaceKacper Michajłow2024-01-221-15/+17
|
* image_writer: default to lossless AVIF screenshotsKacper Michajłow2023-12-041-2/+1
| | | | | Also change the example to crf=23. crf=32 is pretty bad quality, don't give users bad usage ideas.
* image_writer: add missing mp_image_params in convert_imageKacper Michajłow2023-12-041-0/+2
| | | | | | | Fixes chroma location for screenshots. Also set the crop to full frame to not trip mp_image_params_equal check if not necessary.
* image_writer: print screenshot format in verbose logKacper Michajłow2023-12-041-2/+2
| | | | It is useful information, not only for debugging.
* image_writer: use common format selection for AVIF screenshotsKacper Michajłow2023-12-041-2/+2
| | | | --screenshot-avif-pixfmt no longer defaults to yuv420p.
* image_writer: improve format conversion loggingsfan52023-11-071-2/+6
|
* ALL: use pl_hdr_metadata and nuke sig_peakKacper Michajłow2023-11-051-1/+1
| | | | | | | | This commit replaces all uses of sig_peak and maps all HDR metadata. Form notable changes mixed usage of maxCLL and max_luma is resolved and not always max_luma is used which makes vo_gpu and vo_gpu_next behave the same way.
* screenshot: support crop with --screenshot-swKacper Michajłow2023-09-091-2/+18
|
* video_writer: fix gamma for YUV screenshotssfan52023-07-261-2/+2
| | | | | | reproduction steps: take any lossy WebP screenshot and check the colors (or JPEG without libjpeg support, or AVIF with tag-colorspace=no) fixes: 6d9e72cd89652aaf73fa5a8256c439221e86b94a
* image_writer: log pixfmt conversionsfan52023-07-261-0/+2
|
* image_writer: use proper specifier for int64_tNRK2023-07-201-1/+2
|
* image_writer: move tag_csp check into image_writer_flexible_csp()sfan52023-07-191-0/+2
| | | | | | | This ensures the sRGB fallback to happen in all situations involving the image writer code, notably --screenshot-sw. fixes: cbbe2e52210d9885a0897e9c7833267a60456c56
* image_writer: replace sprintf usagesfan52023-07-191-4/+2
| | | | also fixes the buffer being cut off (?!)
* image_writer: share some code between write_lavc and write_avifsfan52023-07-191-45/+39
| | | | | | | As a consequence: - write_avif now respects tag-colorspace=no - write_lavc additionally sets colorspace and chroma_location (of no consequence for png or jpeg)
* image_writer: error check avif-pixfmt optionsfan52023-07-191-0/+5
|
* image_writer: fix still-picture option for AVIFsfan52023-07-191-1/+1
| | | | Gets rid of validation warnings on the produced files.
* image_writer: remove duplicate packet writing codesfan52023-07-191-29/+4
|
* video/image_writer: check for write errorsNRK2023-07-111-3/+2
| | | | | | make sure that fwrite is error checked. and if any data was still remaining on the buffer, it will be flushed - and errors checked - via the fclose() call below.
* video/image_writer: fix file leak in error pathNRK2023-07-111-0/+1
| | | | regression from de7f4fb1e
* video/image_writer: add avif screenshot supportcloud116652023-07-011-17/+293
| | | | | | | | | | Notes: - converts the (image) write() api to filenames, because using avio with FILE* is a pain. - adds more debug logs for screenshots. build: rename av1 dependency to avif_muxer wscript: unify lavf dependency with meson
* image_writer: respect jpeg-quality when using ffmpeg for writingsfan52023-06-291-1/+9
|
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-211-8/+7
| | | | | | c78482045444c488bb7948305d583a55d17cd236 introduced a bool option type as a replacement for the flag type, but didn't actually transition and remove the flag type because it would have been too much mundane work.
* video/image_writer: use effort=4 default for JXL screenshotsLeo Izen2023-02-171-1/+1
| | | | | | effort=4 has a significant increase in quality/bpp compared to effort=3 with a very minor increase in encoding time. It's worth the trade-off as a default setting for lossy encoding.
* video/image_writer: force sRGB for unsupported formatsNiklas Haas2023-02-131-8/+13
| | | | | | | | | After commit c98e7353, we blindly pass the screenshot colorspace to the image writer. But since we want to introduces the ability to save images in HDR and other exotic formats, we should strip this for unsupported formats. See-Also: #10988
* video/image_writer: add image_writer_flexible_cspNiklas Haas2023-02-131-0/+13
| | | | | | PNG only supports this since the introduction of cICP, so put a version check on the next API version bump after the cICP writing patch got merged.
* video/image_writer: change screenshot-tag-colorspace default to yesLeo Izen2023-02-091-1/+1
| | | | | | With significant improvements to the color tagging support in various screenshot formats, e.g. cICP in FFmpeg, and JPEG XL's generally robust color support, it's safe to default this to yes.
* video/image_writer: avoid stripping colorspace info when writing imageLeo Izen2023-01-311-0/+1
| | | | | | | | | | | | | Writing an image either with vo_image or with a screenshot will strip the colorspace info because it allocates a new mp_image that contains the same data as the old image after calling mp_image_params_guess_csp. However, mp_image_params_guess_csp cannot always guess the appropriate colorspace, so it picks a "sane default." Since this function also changes parameters so the space always makes sense, this extra info isn't harmful and allows screenshots and vo_image outs to be properly tagged with the correct colorspace. Fixes #10988.
* video/image_writer: tag colorspace in AVCodecContextLeo Izen2022-05-041-2/+4
| | | | | If screenshot-tag-colorspace=yes, then set the corresponding fields in AVCodecContext, not just in AVFrame.
* video/image_writer: fix high-depth JPEG XL screenshotsLeo Izen2022-04-291-1/+5
| | | | | | | Allow screenshot-high-bit-depth=yes to work with JPEG XL screenshots when screenshot-sw=no is set. They already work as expected when screenshot-sw=yes is set, but this allows the hardware screenshots to work this way too.
* build: add avcodec jpegxl dependency versionsLeo Izen2022-04-281-5/+3
| | | | | Add the libavcodec version check for AV_CODEC_ID_JPEGXL to the build system rather than to any file that references it.
* video/image_writer: add Jpeg XL screenshotsLeo Izen2022-04-261-0/+18
| | | | | | | Add Jpeg XL as a possible output format for screenshots, which should make it possible to take fast screenshots with much better quality than JPEG, or take lossless high-bit-depth screenshots with lower file sizes than PNG.
* image_writer: replace deprecated av_init_packet()sfan52022-01-101-10/+9
|
* build: address AVCodec, AVInputFormat, AVOutputFormat const warningssfan52021-05-011-3/+3
| | | | FFmpeg recently changed these to be const on their side.
* video: clean up some imgfmt related stuffwm42020-05-181-3/+11
| | | | | | | | | | | | | | | | Remove the vaguely defined plane_bits and component_bits fields from struct mp_imgfmt_desc. Add weird replacements for existing uses. Remove the bytes[] field, replace uses with bpp[]. Fix some potential alignment issues in existing code. As a compromise, split mp_image_pixel_ptr() into 2 functions, because I think it's a bad idea to implicitly round, but for some callers being slightly less strict is convenient. This shouldn't really change anything. In fact, it's a 100% useless change. I'm just cleaning up what I started almost 8 years ago (see commit 00653a3eb052). With this I've decided to keep mp_imgfmt_desc, just removing the weird parts, and keeping the saner parts.
* options: change option macros and all option declarationswm42020-03-181-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change all OPT_* macros such that they don't define the entire m_option initializer, and instead expand only to a part of it, which sets certain fields. This requires changing almost every option declaration, because they all use these macros. A declaration now always starts with {"name", ... followed by designated initializers only (possibly wrapped in macros). The OPT_* macros now initialize the .offset and .type fields only, sometimes also .priv and others. I think this change makes the option macros less tricky. The old code had to stuff everything into macro arguments (and attempted to allow setting arbitrary fields by letting the user pass designated initializers in the vararg parts). Some of this was made messy due to C99 and C11 not allowing 0-sized varargs with ',' removal. It's also possible that this change is pointless, other than cosmetic preferences. Not too happy about some things. For example, the OPT_CHOICE() indentation I applied looks a bit ugly. Much of this change was done with regex search&replace, but some places required manual editing. In particular, code in "obscure" areas (which I didn't include in compilation) might be broken now. In wayland_common.c the author of some option declarations confused the flags parameter with the default value (though the default value was also properly set below). I fixed this with this change.
* 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.
* image_writer: add webp-compression optionsfan52019-09-141-0/+3
|
* image_writer: add WebP support (lossy or lossless)sfan52019-09-141-7/+39
|
* image_writer: move convert_image() to player/screenshot.csfan52019-09-141-3/+3
|
* vo_gpu: make screenshots use the GL rendererwm42018-02-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Replace remaining avcodec_close() callswm42017-07-161-3/+1
| | | | | | | | This API isn't deprecated (yet?), but it's still inferior and harder to use than avcodec_free_context(). Leave the call only in 1 case in af_lavcac3enc.c, where we apparently seriously close and reopen the encoder for whatever reason.
* image_writer, vo_image: change license to LGPLwm42017-06-181-10/+7
| | | | | | | | | | | | | | | | | | image_writer.c has code originating from vf_screenshot.c, vo_jpeg.c, and potentially others. vo_image.c is based on a bunch of those VOs as well, and the intention was to replace them with a single codebase. vo_tga.c was written by someone who was not or not could be contacted, but it doesn't matter anyway, as no code from that initial patch was used. One rather old patch (57f77bb41a9) reordered by libjpeg patch API calls, and the author of the patch was not contacted. But at least with the smoothing_factor override removed, this pretty much exactly corresponds to the official libjpeg API example (and might even reflect a change to those - didn't dig deeper). This removes the -jpeg-smooth option. While we're at it, remove all the other dropped jpeg options from the manpage (which was forgotten in past changes).
* image_writer: make it work with libavcodec's jpg encoderwm42017-04-021-5/+38
| | | | | | | | | | | Now taking a screenshot actually works, if libjpeg is disabled at compile time. In particular, the AV_PIX_FMT_YUVJ formats (with the "J") cause us problems. They have been deprecated years ago, but the libavcodec jpg encoder won't accept anything else. This is made worse by the fact that mpv doesn't have J formats internally - it always uses the color levels metadata to decide the range instead.
* screenshot: change details of --screenshot-format handlingwm42017-03-181-45/+41
| | | | | | | | | | | | | | | | 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.)
* image_writer: remove useless formatswm42017-03-181-4/+0
| | | | Nobody cares about those.
* image_writer: check a return valuewm42017-02-201-1/+3
| | | | | Doesn't matter, since it's the flush call, but be nice. In particular, don't upset coverity.
* Remove compatibility thingswm42016-12-071-6/+0
| | | | | | Possible with bumped FFmpeg/Libav. These are just the simple cases.
* vo_image: move to global optionswm42016-09-051-14/+10
| | | | | This is a bit "special", because the config tree wants unique m_sub_options pointers in the whole thing.
* mp_image: split colorimetry metadata into its own structNiklas Haas2016-07-031-2/+2
| | | | | | | | | | | | | | | | | | This has two reasons: 1. I tend to add new fields to this metadata, and every time I've done so I've consistently forgotten to update all of the dozens of places in which this colorimetry metadata might end up getting used. While most usages don't really care about most of the metadata, sometimes the intend was simply to “copy” the colorimetry metadata from one struct to another. With this being inside a substruct, those lines of code can now simply read a.color = b.color without having to care about added or removed fields. 2. It makes the type definitions nicer for upcoming refactors. In going through all of the usages, I also expanded a few where I felt that omitting the “young” fields was a bug.
* image_writer: port to new encode APIwm42016-06-241-0/+12
|
* image_writer: take care of prediction_method deprecationwm42016-02-091-1/+3
| | | | | | | The field was recently deprecated, and you're supposed to set the private codec option instead. Not sure if this really works as intended.
* image_writer: fix writing flipped images as jpgwm42016-01-171-1/+1
| | | | | | next_scanline is usually an unsigned int. Fixes #2635 (again).
* 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-2/+2
| | | | | | | | | | | | | | | | 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).
* Replace deprecated av_free_packet() callswm42015-10-281-1/+1
| | | | | | av_free_packet() got finally deprecated. Use av_packet_unref() instead, which has almost the same semantics, has existed for a while, and is available in all FFmpeg and Libav versions we support.
* image_writer: don't use jpeg baseline, and remove useless jpeg optionswm42015-08-021-6/+1
| | | | | | | | | The jpeg-optimize and jpeg-baseline options were undocumented, and they're also pretty useless. There's no reason to ever change them. Also, don't write jpeg baseline images. This just makes compression worse for the sake of rather questionable compatibility with ancient decoders.
* screenshot: don't write PNG colorspace tags by defaultwm42015-07-181-1/+1
| | | | | | Generates too much discussion and confusion. Fixes #2051.
* screenshots: add option to prevent 16 bit outputwm42015-04-291-13/+23
| | | | That's what it's usually about (again).
* screenshots: add option to disable JPEG 4:4:4 outputwm42015-04-291-2/+6
| | | | That's what it's usually about.
* image_writer: fix writing screenshotswm42015-04-221-1/+1
| | | | | It passed the unconverted image to the writer function. Broken since 2469cb5d.
*