3 import os
, sys
, subprocess
7 JPEG_DIR
= "/home/douglas/sparrow/content/jpg/"
8 ALL_MJPEG_DIR
= "/home/douglas/sparrow/content/mjpeg/"
9 ALL_DF_MJPEG_DIR
= "/home/douglas/sparrow/content/mjpeg_df/"
10 MJPEG_DIR
= "/home/douglas/sparrow/content/selected_mjpeg/"
11 JPEG_NAME_TEMPLATE
= "%03d-%%05d.jpg"
14 def split_mjpeg(src
, dest
):
15 cmd
= ["ffmpeg", "-i", src
,
16 "-vcodec", "copy", dest
,
18 subprocess
.check_call(cmd
)
20 def split_directory(src_dir
, dest_dir
):
21 for i
, src
in enumerate(os
.listdir(src_dir
)):
22 dest
= os
.path
.join(dest_dir
, JPEG_NAME_TEMPLATE
% i
)
23 split_mjpeg(os
.path
.join(src_dir
, src
), dest
)
26 def random_selection(dest
, sf
=0.5, df
=0.1):
28 print "WARNING: %s is not empty" % (dest
,)
30 for f
in os
.listdir(ALL_MJPEG_DIR
):
31 if random
.random() < sf
:
32 os
.link(ALL_MJPEG_DIR
+ f
, MJPEG_DIR
+ f
)
34 for f
in os
.listdir(ALL_DF_MJPEG_DIR
):
35 if random
.random() < df
:
36 os
.link(ALL_DF_MJPEG_DIR
+ f
, MJPEG_DIR
+ 'df+' + f
)
39 #random_selection(MJPEG_DIR, 0.2, 0.05)
40 split_directory(MJPEG_DIR
, JPEG_DIR
)