f.close()
return m.hexdigest() + str(os.path.getsize(filename))
+def command(c):
+ print(f'*** {c}')
+ os.system(c)
+
try:
os.makedirs(os.path.join(sys.argv[1], 'dummy'))
audio_frame_rate = int(c.find('AudioStream').find('FrameRate').text)
audio_length = int(c.find('AudioStream').find('Length').text)
names = { 1: 'mono', 2: 'stereo', 3: '3.0', 4: '4.0', 5: '4.1', 6: '5.1', 7: '6.1', 8: '7.1' }
- audio_cmd = '-f lavfi -i anullsrc=channel_layout=%s:sample_rate=%d' % (names[audio_channels], audio_frame_rate)
+ os.system(f'ffmpeg -t {float(audio_length) / audio_frame_rate} -f lavfi -i anullsrc=channel_layout={names[audio_channels]}:sample_rate={audio_frame_rate} audio.aac')
if c.find('VideoFrameRate') is not None:
video_frame_rate = float(c.find('VideoFrameRate').text)
video_length = int(c.find('VideoLength').text)
video_cmd = '-s qcif -f rawvideo -pix_fmt rgb24 -r %f -i /dev/zero' % video_frame_rate
- os.system('ffmpeg -t %f %s %s -shortest "%s"' % (video_length / video_frame_rate, video_cmd, audio_cmd, path))
+ command(f'ffmpeg -t {video_length / video_frame_rate} -s qcif -f rawvideo -pix_fmt rgb24 -r {video_frame_rate} -i /dev/zero -shortest video.mp4')
+ if c.find('AudioStream') is not None and c.find('VideoFrameRate') is not None:
+ command(f'ffmpeg -i video.mp4 -i audio.aac -c copy -shortest "{path}"')
+ elif c.find('VideoFrameRate') is not None:
+ command(f'ffmpeg -i video.mp4 "{path}"')
else:
- os.system('sox -n -r %d -c %d %s trim 0.0 %f' % (audio_frame_rate, audio_channels, path, float(audio_length) / audio_frame_rate))
+ command('sox -n -r %d -c %d %s trim 0.0 %f' % (audio_frame_rate, audio_channels, path, float(audio_length) / audio_frame_rate))
+ try:
+ os.unlink('video.mp4')
+ os.unlink('audio.aac')
+ except:
+ pass
c.find('Path').text = path
c.find('Digest').text = digest_head_tail(path)
elif type == 'Image':