ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
import bpy
|
||||
|
||||
# Clear default objects
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
bpy.ops.object.delete()
|
||||
|
||||
# Set up scene and sequence editor
|
||||
scene = bpy.context.scene
|
||||
scene.sequence_editor = scene.sequence_editor_create()
|
||||
se = scene.sequence_editor
|
||||
|
||||
# File paths
|
||||
input_path = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/source.mov'
|
||||
output_path = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/negative_control.mp4'
|
||||
|
||||
# Video parameters
|
||||
source_fps = 25
|
||||
trim_start_sec = 0.0
|
||||
trim_end_sec = 3.0
|
||||
trim_duration_sec = trim_end_sec - trim_start_sec
|
||||
trim_duration_frames = int(trim_duration_sec * source_fps) # 75 frames
|
||||
output_duration_sec = trim_duration_sec * 1.5 # 4.5 seconds
|
||||
output_duration_frames = int(output_duration_sec * source_fps) # 113 frames (rounded up from 112.5)
|
||||
|
||||
speed_factor = trim_duration_sec / output_duration_sec # 0.666...
|
||||
|
||||
# Add video strip
|
||||
video_strip = se.sequences.new_movie(
|
||||
name='Video',
|
||||
filepath=input_path,
|
||||
channel=2,
|
||||
frame_start=1
|
||||
)
|
||||
video_strip.frame_offset_start = 0 # Start at 0s of source
|
||||
video_strip.frame_final_duration = trim_duration_frames # Trim to 3 seconds
|
||||
|
||||
# Add audio strip
|
||||
audio_strip = se.sequences.new_sound(
|
||||
name='Audio',
|
||||
filepath=input_path,
|
||||
channel=1,
|
||||
frame_start=1
|
||||
)
|
||||
audio_strip.frame_offset_start = 0
|
||||
audio_strip.frame_final_duration = trim_duration_frames
|
||||
|
||||
# Add speed effect to video
|
||||
speed_video = se.sequences.new_effect(
|
||||
name='Speed_Video',
|
||||
type='SPEED',
|
||||
channel=3,
|
||||
frame_start=1,
|
||||
seq1=video_strip
|
||||
)
|
||||
speed_video.speed_factor = speed_factor
|
||||
speed_video.frame_final_duration = output_duration_frames
|
||||
|
||||
# Add speed effect to audio
|
||||
speed_audio = se.sequences.new_effect(
|
||||
name='Speed_Audio',
|
||||
type='SPEED',
|
||||
channel=2,
|
||||
frame_start=1,
|
||||
seq1=audio_strip
|
||||
)
|
||||
speed_audio.speed_factor = speed_factor
|
||||
speed_audio.frame_final_duration = output_duration_frames
|
||||
|
||||
# Add subtitle text strip
|
||||
text_strip = se.sequences.new_effect(
|
||||
name='Subtitle',
|
||||
type='TEXT',
|
||||
channel=4,
|
||||
frame_start=1,
|
||||
frame_end=1 + output_duration_frames - 1
|
||||
)
|
||||
text_strip.text = 'BIG BUNNY'
|
||||
text_strip.align_x = 'CENTER'
|
||||
text_strip.align_y = 'BOTTOM'
|
||||
text_strip.font_size = 48
|
||||
text_strip.color = (1.0, 1.0, 1.0, 1.0) # White text
|
||||
|
||||
# Subtitle background box
|
||||
text_strip.use_box = True
|
||||
text_strip.box_color = (0.0, 0.0, 0.0, 0.5) # Semi-transparent black
|
||||
text_strip.box_margin_left = 10
|
||||
text_strip.box_margin_right = 10
|
||||
text_strip.box_margin_top = 10
|
||||
text_strip.box_margin_bottom = 10
|
||||
|
||||
# Render settings
|
||||
scene.render.resolution_x = 854
|
||||
scene.render.resolution_y = 480
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.fps = source_fps
|
||||
scene.render.fps_base = 1.0
|
||||
|
||||
# Output format settings
|
||||
scene.render.image_settings.file_format = 'MPEG4'
|
||||
scene.render.ffmpeg.format = 'MPEG4'
|
||||
scene.render.ffmpeg.codec = 'H.264'
|
||||
scene.render.ffmpeg.audio_codec = 'AAC'
|
||||
scene.render.ffmpeg.audio_bitrate = 192
|
||||
scene.render.ffmpeg.constant_rate_factor = 'MEDIUM'
|
||||
scene.render.filepath = output_path
|
||||
|
||||
# Set scene frame range
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = output_duration_frames
|
||||
|
||||
# Render animation
|
||||
bpy.ops.render.render(animation=True)
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
import bpy
|
||||
import math
|
||||
|
||||
# Clear default objects
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
bpy.ops.object.delete()
|
||||
|
||||
# Set up scene
|
||||
scene = bpy.context.scene
|
||||
|
||||
# Render settings
|
||||
scene.render.resolution_x = 854
|
||||
scene.render.resolution_y = 480
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.fps = 25
|
||||
scene.render.fps_base = 1.0
|
||||
scene.render.image_settings.file_format = 'MPEG4'
|
||||
scene.render.ffmpeg.codec = 'H264'
|
||||
scene.render.ffmpeg.audio_codec = 'AAC'
|
||||
scene.render.filepath = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/negative_control.mp4'
|
||||
|
||||
# Set up Video Sequence Editor
|
||||
if not scene.sequence_editor:
|
||||
scene.sequence_editor_create()
|
||||
scene.sequence_editor.sequences.clear()
|
||||
|
||||
# Import source movie
|
||||
input_path = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/source.mov'
|
||||
movie_strip = scene.sequence_editor.sequences.new_movie(
|
||||
name='Source',
|
||||
filepath=input_path,
|
||||
channel=1,
|
||||
frame_start=1
|
||||
)
|
||||
# Trim to 3 seconds (75 frames at 25fps)
|
||||
movie_strip.frame_final_duration = 75
|
||||
|
||||
# Add speed effect (1.5x duration = 2/3 speed)
|
||||
speed_strip = scene.sequence_editor.sequences.new_effect(
|
||||
name='Slow',
|
||||
type='SPEED',
|
||||
channel=2,
|
||||
frame_start=1,
|
||||
frame_end=movie_strip.frame_final_end,
|
||||
seq1=movie_strip
|
||||
)
|
||||
speed_strip.speed_factor = 2/3 # 3s * 1.5 = 4.5s duration
|
||||
|
||||
# Calculate scene frame range
|
||||
slowed_frames = movie_strip.frame_final_duration / speed_strip.speed_factor
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = math.ceil(scene.frame_start + slowed_frames - 1)
|
||||
|
||||
# Create sequence editor if not exists
|
||||
if not scene.sequence_editor:
|
||||
scene.sequence_editor_create()
|
||||
|
||||
# Subtitle background (semi-transparent dark box)
|
||||
color_strip = scene.sequence_editor.sequences.new_effect(
|
||||
name='SubtitleBG',
|
||||
type='COLOR',
|
||||
channel=3,
|
||||
frame_start=scene.frame_start,
|
||||
frame_end=scene.frame_end
|
||||
)
|
||||
color_strip.color = (0.0, 0.0, 0.0) # Black
|
||||
color_strip.alpha = 0.5 # Semi-transparent
|
||||
color_strip.transform.scale_x = 0.4 # Box width
|
||||
color_strip.transform.scale_y = 0.15 # Box height
|
||||
color_strip.transform.translate_y = -0.4 # Bottom position
|
||||
color_strip.transform.align_x = 'CENTER' # Center horizontally
|
||||
|
||||
# Subtitle text
|
||||
text_strip = scene.sequence_editor.sequences.new_effect(
|
||||
name='SubtitleText',
|
||||
type='TEXT',
|
||||
channel=4,
|
||||
frame_start=scene.frame_start,
|
||||
frame_end=scene.frame_end
|
||||
)
|
||||
text_strip.text = 'BIG BUNNY'
|
||||
text_strip.align_x = 'CENTER'
|
||||
text_strip.align_y = 'CENTER'
|
||||
text_strip.font_size = 40
|
||||
text_strip.color = (1.0, 1.0, 1.0) # White text
|
||||
text_strip.transform.translate_y = -0.4 # Match background Y position
|
||||
text_strip.transform.align_x = 'CENTER'
|
||||
|
||||
# Render animation
|
||||
bpy.ops.render.render(animation=True)
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
import bpy
|
||||
|
||||
# Clear existing data to start fresh
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
|
||||
# Get the current scene
|
||||
scene = bpy.context.scene
|
||||
|
||||
# Set render resolution and FPS
|
||||
scene.render.resolution_x = 854
|
||||
scene.render.resolution_y = 480
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.fps = 25
|
||||
scene.render.fps_base = 1.0
|
||||
|
||||
# Set render output settings
|
||||
scene.render.image_settings.file_format = 'FFMPEG'
|
||||
scene.render.ffmpeg.format = 'MPEG4'
|
||||
scene.render.ffmpeg.codec = 'H264'
|
||||
scene.render.ffmpeg.audio_codec = 'AAC'
|
||||
scene.render.ffmpeg.constant_rate_factor = 'MEDIUM'
|
||||
scene.render.filepath = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/negative_control.mp4'
|
||||
|
||||
# Create sequence editor
|
||||
scene.sequence_editor_create()
|
||||
seq_ed = scene.sequence_editor
|
||||
|
||||
# Input movie path
|
||||
input_movie = '/Users/boj/book/ai-agent-book/chapter5/video-edit/validation/runs/exp5-6-real-blender-20260730-050817/source.mov'
|
||||
|
||||
# Add video strip with trim (0.000-3.000s = 0-75 frames at 25fps)
|
||||
video_strip = seq_ed.sequences.new_movie(name='Video', filepath=input_movie, channel=1, frame_start=0)
|
||||
video_strip.frame_offset_start = 0 # Start at source frame 0
|
||||
video_strip.frame_final_duration = 75 # 3s * 25fps = 75 frames
|
||||
|
||||
# Add speed effect to slow down (1.5x duration: 3s → 4.5s = 112.5 frames → 113 frames)
|
||||
speed_effect = seq_ed.sequences.new_effect(name='Speed', type='SPEED', channel=2, frame_start=0, frame_end=113, seq1=video_strip)
|
||||
speed_effect.speed_factor = 2/3 # Slows to 1.5x original duration
|
||||
|
||||
# Add audio strip from movie
|
||||
audio_strip = seq_ed.sequences.new_sound(name='Audio', filepath=input_movie, channel=1, frame_start=0)
|
||||
audio_strip.frame_offset_start = 0 # Match video trim start
|
||||
audio_strip.frame_final_duration = 75 # Match video trim duration
|
||||
|
||||
# Add speed effect to audio
|
||||
audio_speed = seq_ed.sequences.new_effect(name='AudioSpeed', type='SPEED', channel=2, frame_start=0, frame_end=113, seq1=audio_strip)
|
||||
audio_speed.speed_factor = 2/3
|
||||
audio_speed.use_audio = True
|
||||
|
||||
# Create subtitle background (semi-transparent dark box)
|
||||
bg_strip = seq_ed.sequences.new_effect(name='SubtitleBG', type='COLOR', channel=3, frame_start=0, frame_end=113)
|
||||
bg_strip.color = (0.1, 0.1, 0.1, 0.7) # Dark gray with 70% transparency
|
||||
bg_strip.align_x = 'CENTER'
|
||||
bg_strip.align_y = 'BOTTOM'
|
||||
bg_strip.transform.scale_x = 0.5 # Width of background box
|
||||
bg_strip.transform.scale_y = 0.15 # Height of background box
|
||||
bg_strip.transform.location_y = 0.03 # Position slightly above bottom edge
|
||||
|
||||
# Create subtitle text
|
||||
text_strip = seq_ed.sequences.new_effect(name='SubtitleText', type='TEXT', channel=4, frame_start=0, frame_end=113)
|
||||
text_strip.text = 'BIG BUNNY'
|
||||
text_strip.align_x = 'CENTER'
|
||||
text_strip.align_y = 'BOTTOM'
|
||||
text_strip.font_size = 48
|
||||
text_strip.color = (1.0, 1.0, 1.0) # White text
|
||||
text_strip.transform.location_y = 0.05 # Align with background box
|
||||
|
||||
# Set scene frame range to cover slowed duration (4.5 seconds = 112.5 frames → 113 frames)
|
||||
scene.frame_start = 0
|
||||
scene.frame_end = 113
|
||||
|
||||
# Render the animation
|
||||
bpy.ops.render.render(animation=True)
|
||||
Reference in New Issue
Block a user