|
40 | 40 |
|
41 | 41 | __author__ = 'Harald Hetzner' |
42 | 42 | __license__ = 'BSD 3-Clause License' |
43 | | -__version__ = '2.0.4' |
| 43 | +__version__ = '2.1.0' |
44 | 44 |
|
45 | 45 | class Parameters: |
46 | 46 | """ |
@@ -752,6 +752,17 @@ def create_preview_thumbnails_for(self, file_path: Path) -> Image: |
752 | 752 | video_width = int(video_metadata['width']) |
753 | 753 | # Height in px |
754 | 754 | video_height = int(video_metadata['height']) |
| 755 | + # Rotation in ° |
| 756 | + video_rotation = 0 |
| 757 | + if 'rotation' in video_metadata.keys(): |
| 758 | + video_rotation = int(float(video_metadata['rotation'])) |
| 759 | + if self.parameters.verbose: |
| 760 | + print('Video images are rotated by {}° according to metadata.'.format(video_rotation)) |
| 761 | + # Swap width and height if the video is rotated by 90° or 270° |
| 762 | + if video_rotation in (90, 270): |
| 763 | + temp = video_width |
| 764 | + video_width = video_height |
| 765 | + video_height = temp |
755 | 766 | # Aspect ratio |
756 | 767 | video_aspect = float(video_width) / float(video_height) |
757 | 768 | # Frames per second |
@@ -959,7 +970,11 @@ def create_preview_thumbnails_for(self, file_path: Path) -> Image: |
959 | 970 | # pts = presentation timestamp in time_base units |
960 | 971 | if frame.pts >= target_timestamp: |
961 | 972 | # VideoFrame.to_image() returns a PIL image |
962 | | - image = frame.to_image().resize((thumbnail_width, thumbnail_height)) |
| 973 | + image = frame.to_image() |
| 974 | + # Counterrotate the image if the video is rotated by multiples of 90° according to metadata |
| 975 | + if video_rotation in (90, 180, 270): |
| 976 | + image = image.rotate(-video_rotation, expand=True) |
| 977 | + image = image.resize((thumbnail_width, thumbnail_height)) |
963 | 978 | thumbnails_image.paste(image, box=(x, y)) |
964 | 979 | frame_captured = True |
965 | 980 | break |
|
0 commit comments