X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=hacks%2Fmake_dummy_files;h=21c09e2eae7f84f2e492c6159bacadd55ce9ec1e;hb=0697f5820b07046b4502806f7c085dfc4596ee4c;hp=1370fff98827d37f4fac0f37582b546d59a7509d;hpb=55e137bfa7a7a4c394cce9e396a89e81f16b388a;p=dcpomatic.git diff --git a/hacks/make_dummy_files b/hacks/make_dummy_files index 1370fff98..21c09e2ea 100755 --- a/hacks/make_dummy_files +++ b/hacks/make_dummy_files @@ -24,6 +24,10 @@ def digest_head_tail(filename, size=1000000): 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')) @@ -110,16 +114,28 @@ for c in root.find('Playlist').findall('Content'): video_cmd = '' audio_cmd = '' path = os.path.join(sys.argv[1], 'dummy', ntpath.basename(c.find('Path').text)) - 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 %d -i /dev/zero' % video_frame_rate if c.find('AudioStream') is not None: audio_channels = int(c.find('AudioStream').find('Mapping').find('InputChannels').text) 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('ffmpeg -t %d %s %s -shortest "%s"' % (float(video_length) / video_frame_rate, video_cmd, audio_cmd, path)) + 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 + 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: + 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':