Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pixiv] Retaining ugoira_meta(.json) and Losslessly Converting Ugoira to Video Format When Downloading Pixiv Ugoira #6909

Closed
tglsf opened this issue Jan 31, 2025 · 7 comments

Comments

@tglsf
Copy link

tglsf commented Jan 31, 2025

Retaining ugoira_meta(.json) When Downloading Pixiv Ugoira

  1. Currently, when downloading Pixiv ugoira, the program does not retain ugoira_meta(.json), which contains the duration of each frame. Sometimes, I need this metadata for manual image conversion.

  2. When downloading ugoira as a ZIP file, no FPS or frame delay information is included. If exported as GIF or MP4, the program assigns a constant frame rate. However, some ugoira animations do not use a constant frame rate, which is why I perform manual conversion.

Losslessly Converting Ugoira to Video Format

  1. The program currently converts ugoira to H.264, but we can instead convert it to MJPEG using stream copy, making the process lossless:

ffmpeg -framerate 30 -i %6d.jpg -c copy out.mkv

  1. Using VFR Mode: As mentioned earlier, some ugoira animations do not use a constant frame rate, meaning each frame has a different duration. I usually use the following command to save the video in VFR mode:

ffmpeg -f concat -safe 0 -i inputlist.txt -sws_flags lanczos+bitexact+full_chroma_int+full_chroma_inp+accurate_rnd -fps_mode vfr -c libx264 -preset slower -crf 24 -color_range 2 -pix_fmt yuv420p -movflags +write_colr out.mp4
Content of inputlist.txt:

file 'C:\input\000000.jpg'
duration 0.05
file 'C:\input\000001.jpg'
duration 0.10
...

(Using this method, redundant frames can also be removed with -vf mpdecimate=hi=1:lo=1:frac=1:max=0:keep=0, further reducing storage space.)

@mikf
Copy link
Owner

mikf commented Jan 31, 2025

You can achieve most, maybe even all, of what you listed with appropriate config and ugoira post processor settings (see https://gdl-org.github.io/docs/configuration.html) and having a mkvmerge binary in PATH. #6147 has some more useful information.

To get "simple" lossless ugoira, even -o ugoira=original --ugoira copy as CLI options would be enough.

{
    "extractor": {
        "pixiv": {
            "ugoira": "original",
            "postprocessors": [
                {
                    "name": "metadata",
                    "event": "post,skip",
                    "filename": "{id}.json"
                },
                {
                    "name": "ugoira",
                    "metadata": true,
                    "keep-files": true,
                    "extension": "mkv",
                    "ffmpeg-args": ["-c", "copy"]
                },
                {
                    "name": "ugoira",
                    "mode": "archive",
                    "metadata": true,
                    "keep-files": false
                }
            ]
        }
    }
}

@Hrxn
Copy link
Contributor

Hrxn commented Feb 1, 2025

                {
                    "name": "ugoira",
                    "metadata": true,
                    "keep-files": true,
                    "extension": "mkv",
                    "ffmpeg-args": ["-c", "copy"]
                },

What does "metadata": true do here, isn't this only useful for "mode": "archive" ugoira post-processors?

@tglsf
Copy link
Author

tglsf commented Feb 1, 2025

@mikf

Thank you for your helpful reply.

When using mkvmerge, it seems to use my temp directory. I want it to run in my RAM disk instead of the hard drive to speed up processing and reduce disk writes. Is there an option to change this setting?

@mikf
Copy link
Owner

mikf commented Feb 1, 2025

@Hrxn
You are correct. "metadata": true doesn't do anything here, but it at least doesn't hurt to have it enabled just in case.

@tglsf
There is no direct option to set the temp directory location, but you should be able to influence it using environment variables: tempfile.gettempdir()

@1223334444abc
Copy link

It is still recommended that when using "ugoira": "original", you should be able to obtain the specific interval for each frame and write it into the image file name.

@mikf
Copy link
Owner

mikf commented Feb 3, 2025

Use an f-string and access {frames[num]['delay']}

$ gallery_dl -f "\fF {id}_p{num}_{frames[num]['delay']}ms.{extension}" -o ugoira=original https://www.pixiv.net/artworks/101003492
./pixiv/14164502 1586611428/101003492_p0_125ms.png
./pixiv/14164502 1586611428/101003492_p1_125ms.png
...

@1223334444abc
Copy link

Use an f-string and access {frames[num]['delay']}

$ gallery_dl -f "\fF {id}_p{num}_{frames[num]['delay']}ms.{extension}" -o ugoira=original https://www.pixiv.net/artworks/101003492
./pixiv/14164502 1586611428/101003492_p0_125ms.png
./pixiv/14164502 1586611428/101003492_p1_125ms.png
...

This worked, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants