Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit db0c2f9

Browse files
Merge pull request #618 from valterm/Unwrap_video
create unwrap script
2 parents ee13c82 + f16e26a commit db0c2f9

File tree

7 files changed

+74
-0
lines changed

7 files changed

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /