Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit d11b546

Browse files
committed
create unwrap script
1 parent ee13c82 commit d11b546

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# unwrap.py
2+
3+
Unwraps a video into a flattened texture using ffmpeg.
4+
5+
### Prerequisites
6+
```pip3 install pillow```
7+
ffmpeg, available from [here.](https://ffmpeg.org)
8+
9+
### How to run the script
10+
Move the videos you want unwrapped into the media directory, then run:
11+
```python3 unwrap.py```
12+
13+
### Screenshot/GIF showing the sample use of the script
14+
Example video is located in media.
15+
16+
This might not look like much, but with better source videos the unwrapped picture will be more meaningful too.
17+
![result](/media/IMG_6610.MOV_unwrapped.jpeg)
18+
19+
## *Author Name*
20+
<!--Remove the below lines and add yours -->
21+
Made with ♥ by [valterm](github.com/valterm)
17.7 MB
Binary file not shown.
91 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow==8.0.1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from PIL import Image
2+
import glob, os, subprocess
3+
4+
#process each video in media folder
5+
for video in glob.glob('media/*'):
6+
#only process videos, ignore generated images
7+
if not 'jpeg' in video:
8+
#get video resolution
9+
result = subprocess.run(['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=s=,:p=0', video], stdout=subprocess.PIPE)
10+
resolution = result.stdout.decode('utf-8')
11+
height,width = resolution.split(',')
12+
height = int(height)
13+
width = int(width)
14+
15+
#from each frame of the video, grab the center pixels and store them temporarily
16+
os.system('ffmpeg -i ' + video +' -filter:v "crop=2:' + str(height) + ':' + str(width/2) + ':1" -q:v 1 tmp/images-%04d.jpeg')
17+
18+
#define the series of images to be processed from the temp images
19+
series = glob.glob("tmp/*.jpeg")
20+
#the composite will be as wide as the number of images
21+
image_size = (len(series), height)
22+
#Create empty image
23+
composite = Image.new("RGB", image_size)
24+
pix_col = 0
25+
26+
#loop through the images and fill the composite
27+
for tmp_img in series:
28+
file, ext = os.path.splitext(tmp_img)
29+
image = Image.open(tmp_img)
30+
image_strip = image.crop( (0, 0, 1, height) )
31+
composite.paste(image_strip, (pix_col, 0))
32+
#pix_col is used to keep track of where the 'building' of the image is, from left to right by pixels
33+
pix_col += 1
34+
image.close()
35+
os.remove(tmp_img)
36+
37+
#save composite
38+
composite.save(video + '_unwrapped.jpeg', 'JPEG')
39+

0 commit comments

Comments
 (0)