Skip to content

Commit b0bc78d

Browse files
authored
Merge pull request #80 from UTMIST/revert-77-audio-video-fi
Revert "fix: audio output in demo_match video"
2 parents 4dedca0 + 5cee37b commit b0bc78d

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

environment/agent.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import skvideo
3535
import skvideo.io
3636
from IPython.display import Video
37-
import subprocess
3837

3938
from stable_baselines3.common.monitor import Monitor
4039

@@ -700,6 +699,7 @@ def close(self):
700699

701700
# In[ ]:
702701

702+
703703
from stable_baselines3.common.vec_env import DummyVecEnv
704704
from tqdm import tqdm
705705

@@ -713,8 +713,8 @@ def run_match(agent_1: Agent | partial,
713713
reward_manager: Optional[RewardManager]=None,
714714
train_mode=False
715715
) -> MatchStats:
716-
717716
# Initialize env
717+
718718
env = WarehouseBrawl(resolution=resolution, train_mode=train_mode)
719719
env.max_timesteps = max_timesteps
720720
observations, infos = env.reset()
@@ -740,16 +740,13 @@ def run_match(agent_1: Agent | partial,
740740
else:
741741
print(f"video_path={video_path} -> Rendering")
742742
# Initialize video writer
743-
writer = skvideo.io.FFmpegWriter(
744-
video_path,
745-
outputdict={
746-
'-vcodec': 'libx264',
747-
'-pix_fmt': 'yuv420p',
748-
'-preset': 'fast',
749-
'-crf': '20',
750-
'-r': '30'
751-
}
752-
)
743+
writer = skvideo.io.FFmpegWriter(video_path, outputdict={
744+
'-vcodec': 'libx264', # Use H.264 for Windows Media Player
745+
'-pix_fmt': 'yuv420p', # Compatible with both WMP & Colab
746+
'-preset': 'fast', # Faster encoding
747+
'-crf': '20', # Quality-based encoding (lower = better quality)
748+
'-r': '30' # Frame rate
749+
})
753750

754751
# If partial
755752
if callable(agent_1):
@@ -790,23 +787,6 @@ def run_match(agent_1: Agent | partial,
790787

791788
if video_path is not None:
792789
writer.close()
793-
794-
# Create a temporary file path in the same folder
795-
temp_path = video_path + ".temp.mp4"
796-
797-
subprocess.run([
798-
"ffmpeg", "-y",
799-
"-i", video_path,
800-
"-i", "environment/assets/soundtrack.mp3",
801-
"-c:v", "copy",
802-
"-c:a", "aac",
803-
"-shortest",
804-
temp_path
805-
])
806-
807-
# Replace the original file with the new one
808-
os.replace(temp_path, video_path)
809-
810790
env.close()
811791

812792
# visualize

0 commit comments

Comments
 (0)