Try to make more accurate video+audio dummy files.
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Aug 2022 20:09:17 +0000 (22:09 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 25 Aug 2022 20:09:17 +0000 (22:09 +0200)
hacks/make_dummy_files

index 4cbc88d2d0ac615fb3d3aa5ff0156fbb4bb9d5c5..21c09e2eae7f84f2e492c6159bacadd55ce9ec1e 100755 (executable)
@@ -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':