sticker-convert 2.7.12__py3-none-any.whl → 2.7.13__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,8 @@ from sticker_convert.utils.media.codec_info import CodecInfo
19
19
  from sticker_convert.utils.media.format_verify import FormatVerify
20
20
 
21
21
  if TYPE_CHECKING:
22
- from av.video.frame import VideoFrame # type: ignore
23
- from av.video.plane import VideoPlane # type: ignore
22
+ from av.video.frame import VideoFrame
23
+ from av.video.plane import VideoPlane
24
24
 
25
25
  MSG_START_COMP = "[I] Start compressing {} -> {}"
26
26
  MSG_SKIP_COMP = "[S] Compatible file found, skip compress and just copy {} -> {}"
@@ -264,14 +264,21 @@ class StickerConvert:
264
264
  self.result_size = self.size
265
265
  self.result_step = step_current
266
266
 
267
- if step_upper - step_lower > 1 and self.size_max:
267
+ if (
268
+ step_upper - step_lower > 0
269
+ and step_current != step_lower
270
+ and self.size_max
271
+ ):
268
272
  if self.size <= self.size_max:
269
273
  sign = "<"
270
274
  step_upper = step_current
271
275
  else:
272
276
  sign = ">"
273
277
  step_lower = step_current
274
- step_current = int(rounding((step_lower + step_upper) / 2))
278
+ if step_current == step_lower + 1:
279
+ step_current = step_lower
280
+ else:
281
+ step_current = int(rounding((step_lower + step_upper) / 2))
275
282
  self.recompress(sign)
276
283
  elif self.result:
277
284
  return self.compress_done(self.result, self.result_step)
@@ -409,7 +416,7 @@ class StickerConvert:
409
416
 
410
417
  if suffix in (".tgs", ".lottie", ".json"):
411
418
  self._frames_import_lottie()
412
- elif suffix in (".webp", ".apng", "png"):
419
+ elif suffix in (".webp", ".apng", ".png", ".gif"):
413
420
  # ffmpeg do not support webp decoding (yet)
414
421
  # ffmpeg could fail to decode apng if file is buggy
415
422
  self._frames_import_pillow()
@@ -431,6 +438,7 @@ class StickerConvert:
431
438
  from av.codec.context import CodecContext
432
439
  from av.container.input import InputContainer
433
440
  from av.video.codeccontext import VideoCodecContext
441
+ from av.video.frame import VideoFrame
434
442
 
435
443
  # Crashes when handling some webm in yuv420p and convert to rgba
436
444
  # https://github.com/PyAV-Org/PyAV/issues/1166
@@ -451,19 +459,31 @@ class StickerConvert:
451
459
 
452
460
  for packet in container.demux(container.streams.video):
453
461
  for frame in context.decode(packet):
454
- if frame.width % 2 != 0:
455
- width = frame.width - 1
456
- else:
457
- width = frame.width
462
+ width_orig = frame.width
463
+ height_orig = frame.height
458
464
 
459
- if frame.height % 2 != 0:
460
- height = frame.height - 1
461
- else:
462
- height = frame.height
465
+ # Need to pad frame to even dimension first
466
+ if width_orig % 2 == 1 or height_orig % 2 == 1:
467
+ from av.filter import Graph
468
+
469
+ width_new = width_orig + width_orig % 2
470
+ height_new = height_orig + height_orig % 2
471
+
472
+ graph = Graph()
473
+ in_src = graph.add_buffer(template=container.streams.video[0])
474
+ pad = graph.add(
475
+ "pad", f"{width_new}:{height_new}:0:0:color=#00000000"
476
+ )
477
+ in_src.link_to(pad)
478
+ sink = graph.add("buffersink")
479
+ pad.link_to(sink)
480
+ graph.configure()
481
+
482
+ graph.push(frame)
483
+ frame = cast(VideoFrame, graph.pull())
463
484
 
464
485
  if frame.format.name == "yuv420p":
465
486
  rgb_array = frame.to_ndarray(format="rgb24")
466
- cast("np.ndarray[Any, Any]", rgb_array)
467
487
  rgba_array = np.dstack(
468
488
  (
469
489
  rgb_array,
@@ -475,13 +495,13 @@ class StickerConvert:
475
495
  # Not safe to directly call frame.to_ndarray(format="rgba")
476
496
  # https://github.com/laggykiller/sticker-convert/issues/114
477
497
  frame = frame.reformat(
478
- width=width,
479
- height=height,
480
498
  format="yuva420p",
481
499
  dst_colorspace=1,
482
500
  )
483
501
  rgba_array = yuva_to_rgba(frame)
484
502
 
503
+ # Remove pixels that was added to make dimensions even
504
+ rgba_array = rgba_array[0:width_orig, 0:height_orig]
485
505
  self.frames_raw.append(rgba_array)
486
506
 
487
507
  def _frames_import_lottie(self) -> None:
@@ -727,10 +747,10 @@ class StickerConvert:
727
747
  if 0 in alpha:
728
748
  extra_kwargs["transparency"] = 0
729
749
  extra_kwargs["disposal"] = 2
730
- im_out = [self.quantize(Image.fromarray(i)) for i in frames_processed]
750
+ im_out = [self.quantize(Image.fromarray(i)) for i in frames_processed] # type: ignore
731
751
  else:
732
752
  im_out = [
733
- self.quantize(Image.fromarray(i).convert("RGB")).convert("RGB")
753
+ self.quantize(Image.fromarray(i).convert("RGB")).convert("RGB") # type: ignore
734
754
  for i in frames_processed
735
755
  ]
736
756
 
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env python3
2
2
 
3
- __version__ = "2.7.12"
3
+ __version__ = "2.7.13"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sticker-convert
3
- Version: 2.7.12
3
+ Version: 2.7.13
4
4
  Summary: Convert (animated) stickers to/from WhatsApp, Telegram, Signal, Line, Kakao, iMessage. Written in Python.
5
5
  Author-email: laggykiller <chaudominic2@gmail.com>
6
6
  Maintainer-email: laggykiller <chaudominic2@gmail.com>
@@ -1,12 +1,12 @@
1
1
  sticker_convert/__init__.py,sha256=iQnv6UOOA69c3soAn7ZOnAIubTIQSUxtq1Uhh8xRWvU,102
2
2
  sticker_convert/__main__.py,sha256=6RJauR-SCSSTT3TU7FFB6B6PVwsCxO2xZXtmZ3jc2Is,463
3
3
  sticker_convert/cli.py,sha256=kyfhvMoHq42uLZsYYLrr6b30xsNE93GVZlbGYPFjC2I,18385
4
- sticker_convert/converter.py,sha256=-BxUT-VCw-VbfbG7ZZxNTI4FIJcU3Pq2rzw0VuitiVI,32904
4
+ sticker_convert/converter.py,sha256=XqJyHPWaZCZEbUK_-0CUYmumeUzgOS4lg7zTPH9JYA8,33821
5
5
  sticker_convert/definitions.py,sha256=ZhP2ALCEud-w9ZZD4c3TDG9eHGPZyaAL7zPUsJAbjtE,2073
6
6
  sticker_convert/gui.py,sha256=TqdgFbHBRYgcXWWrsfxLUJ8Zu9WeE11vYyZMX6nalik,30599
7
7
  sticker_convert/job.py,sha256=J4e7dZ48t5EhM3fG-xF1BEQ10WYljx3wWamKXAJjCa8,26000
8
8
  sticker_convert/job_option.py,sha256=1YVhyTfu2cWz3qpAKbdIM11jbL0CJz0ksOYAeg8v6dc,7649
9
- sticker_convert/version.py,sha256=itLv7GvtbPZ961xSemMjepArEGEJR3yg6PpGH0MuovQ,47
9
+ sticker_convert/version.py,sha256=jOLhRKwMOcmLYOtzpH73qVOpP1okliTWPuuIgfNT8xw,47
10
10
  sticker_convert/downloaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  sticker_convert/downloaders/download_base.py,sha256=5R7c8kwahAflOOYrtSQPnBVQ4T-DsprPUMP7G9wcJX4,2824
12
12
  sticker_convert/downloaders/download_kakao.py,sha256=RYrebTxEjKjXAr9xw18r0dMW0dFjSqZxzi8dpaq56TY,8581
@@ -92,9 +92,9 @@ sticker_convert/utils/media/apple_png_normalize.py,sha256=LbrQhc7LlYX4I9ek4XJsZE
92
92
  sticker_convert/utils/media/codec_info.py,sha256=JHHlfCLSpepYFv6TSL1XqwUJoVOpOPFxurRtduplPGY,12856
93
93
  sticker_convert/utils/media/decrypt_kakao.py,sha256=4wq9ZDRnFkx1WmFZnyEogBofiLGsWQM_X69HlA36578,1947
94
94
  sticker_convert/utils/media/format_verify.py,sha256=Xf94jyqk_6M9IlFGMy0wYIgQKn_yg00nD4XW0CgAbew,5732
95
- sticker_convert-2.7.12.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
96
- sticker_convert-2.7.12.dist-info/METADATA,sha256=tJ1IQvfsDyRiDDQSkHech1YhfhlB9U9HPeUEk5a15eY,49133
97
- sticker_convert-2.7.12.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
98
- sticker_convert-2.7.12.dist-info/entry_points.txt,sha256=MNJ7XyC--ugxi5jS1nzjDLGnxCyLuaGdsVLnJhDHCqs,66
99
- sticker_convert-2.7.12.dist-info/top_level.txt,sha256=r9vfnB0l1ZnH5pTH5RvkobnK3Ow9m0RsncaOMAtiAtk,16
100
- sticker_convert-2.7.12.dist-info/RECORD,,
95
+ sticker_convert-2.7.13.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
96
+ sticker_convert-2.7.13.dist-info/METADATA,sha256=dwERdM02NVAJqK7mBwQjAaWMipbyJVr-IRIzSSKJY98,49133
97
+ sticker_convert-2.7.13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
98
+ sticker_convert-2.7.13.dist-info/entry_points.txt,sha256=MNJ7XyC--ugxi5jS1nzjDLGnxCyLuaGdsVLnJhDHCqs,66
99
+ sticker_convert-2.7.13.dist-info/top_level.txt,sha256=r9vfnB0l1ZnH5pTH5RvkobnK3Ow9m0RsncaOMAtiAtk,16
100
+ sticker_convert-2.7.13.dist-info/RECORD,,