From df94adbf7373374aa1b01bfe5414c61e60ea5e26 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Aug 2022 22:09:17 +0200 Subject: [PATCH] Try to make more accurate video+audio dummy files. --- hacks/make_dummy_files | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hacks/make_dummy_files b/hacks/make_dummy_files index 4cbc88d2d..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')) @@ -115,14 +119,23 @@ for c in root.find('Playlist').findall('Content'): 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': -- 2.30.2