Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test_opencl_*.py
test_xfade_opencl.py
create_opencl_*.py
OPENCL_SETUP_GUIDE.md
test-slideshow-local/

# Python cache
__pycache__/
Expand Down
Binary file added debug_frame_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added debug_frame_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added debug_frame_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_0.8s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_0001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_0002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_0003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_0004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_1.0s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_1.2s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_1.8s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_2.0s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_2.2s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_2.8s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_3.0s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frames/frame_3.2s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/064-laser-thum_hYpSdXS.mp3
Binary file not shown.
Binary file added real_content_demo/amex_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/amex_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/continuum of work location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added real_content_demo/gc_banner.png
20 changes: 17 additions & 3 deletions src/slideshow_maker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,30 @@ def detect_nvenc_support():
if os.environ.get("PYTEST_CURRENT_TEST"):
return False
ffmpeg_path = get_ffmpeg_path()

try:
# Check if h264_nvenc encoder is available (hard timeout)
cmd = f'"{ffmpeg_path}" -hide_banner -encoders 2>&1'
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=1)
if result.returncode == 0 and 'h264_nvenc' in result.stdout:
if result.returncode != 0 or 'h264_nvenc' not in result.stdout:
return False

# Additional runtime test: Try to actually encode a tiny clip
# This catches cases where encoder is listed but CUDA libs are missing
test_cmd = f'"{ffmpeg_path}" -y -f lavfi -i "color=black:size=32x32:duration=0.1" -c:v h264_nvenc -f null - 2>&1'
test_result = subprocess.run(test_cmd, shell=True, capture_output=True, text=True, timeout=5)

# Check both stdout and stderr for CUDA errors
combined_output = test_result.stdout + test_result.stderr
cuda_error = "Cannot load libcuda.so.1" in combined_output

# If the test succeeds (no CUDA errors), NVENC is truly available
if test_result.returncode == 0 and not cuda_error:
return True

except Exception:
pass

return False


Expand Down
113 changes: 44 additions & 69 deletions src/slideshow_maker/video_chunked.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,76 +119,51 @@ def create_slideshow_chunked(images: List[str], output_file: str, min_duration:
shutil.move(temp_clips[0], chunk_file)
else:
print(f" 🎭 Creating VARIED smooth transitions between {len(temp_clips)} images...")
print(f" ✨ Creating REAL VARIED transitions")
transition_clips: List[str] = []

for j in range(len(temp_clips)):
if j == 0:
transition_clips.append(temp_clips[j])
else:
prev_clip = temp_clips[j-1]
curr_clip = temp_clips[j]
transition_file = f"{temp_dir}/transition_{chunk_idx}_{j}.mp4"
# Choose a transition that is supported by current ffmpeg (probe once)
candidates = available_transitions[:]
random.shuffle(candidates)
transition_type = None
for cand in candidates:
test_cmd = f'ffmpeg -v error -f lavfi -i "color=red:size=320x240:duration=2" -f lavfi -i "color=blue:size=320x240:duration=2" -filter_complex "[0:v][1:v]xfade=transition={cand}:duration=1.0:offset=1.0" -t 1 -f null -'
if run_command(test_cmd, f" Probe transition {cand}", show_output=False):
transition_type = cand
break
if transition_type is None:
# Fallback to a safe transition
transition_type = 'fade'
if capabilities['gpu_transitions_supported']:
cmd = f'ffmpeg -y -init_hw_device opencl=ocl:0.0 -filter_hw_device ocl -i "{prev_clip}" -i "{curr_clip}" -filter_complex "[0:v]format=rgba,hwupload=extra_hw_frames=16[0hw];[1:v]format=rgba,hwupload=extra_hw_frames=16[1hw];[0hw][1hw]xfade_opencl=transition={transition_type}:duration={DEFAULT_TRANSITION_DURATION}:offset={duration-DEFAULT_TRANSITION_DURATION:.1f},hwdownload,format=yuv420p" -c:v libx264 -r {fps} -crf {DEFAULT_CRF} -preset {DEFAULT_PRESET} -t {duration:.1f} "{transition_file}"'
else:
encoding_params = get_encoding_params(nvenc_available, fps)
cmd = f'ffmpeg -y -i "{prev_clip}" -i "{curr_clip}" -filter_complex "[0:v][1:v]xfade=transition={transition_type}:duration={DEFAULT_TRANSITION_DURATION}:offset={duration-DEFAULT_TRANSITION_DURATION:.1f}" {encoding_params} -t {duration:.1f} "{transition_file}"'

print(f" πŸ”„ {transition_type.upper()} transition command: {cmd}")
ok_t = run_command(cmd, f" {transition_type.upper()} transition {j}/{len(temp_clips)-1}", show_output=True)
if ok_t:
transition_clips.append(transition_file)
print(f" βœ… {transition_type.upper()} transition {j} SUCCESS")
else:
if capabilities['gpu_transitions_supported'] and capabilities['cpu_transitions_supported']:
print(f" ⚠️ OpenCL transition failed, trying CPU fallback...")
encoding_params = get_encoding_params(nvenc_available, fps)
cpu_cmd = f'ffmpeg -y -i "{prev_clip}" -i "{curr_clip}" -filter_complex "[0:v][1:v]xfade=transition={transition_type}:duration={DEFAULT_TRANSITION_DURATION}:offset={duration-DEFAULT_TRANSITION_DURATION:.1f}" {encoding_params} -t {duration:.1f} "{transition_file}"'
ok_cpu = run_command(cpu_cmd, f" CPU fallback {transition_type.upper()} transition {j}/{len(temp_clips)-1}", show_output=True)
if not ok_cpu and nvenc_available:
# Try forced libx264 if NVENC path in encoding_params failed
cpu_params2 = get_encoding_params(False, fps)
cpu_cmd2 = f'ffmpeg -y -i "{prev_clip}" -i "{curr_clip}" -filter_complex "[0:v][1:v]xfade=transition={transition_type}:duration={DEFAULT_TRANSITION_DURATION}:offset={duration-DEFAULT_TRANSITION_DURATION:.1f}" {cpu_params2} -t {duration:.1f} "{transition_file}"'
ok_cpu = run_command(cpu_cmd2, f" CPU fallback-2 {transition_type.upper()} transition {j}/{len(temp_clips)-1}", show_output=True)
if ok_cpu:
transition_clips.append(transition_file)
print(f" βœ… CPU fallback {transition_type.upper()} transition {j} SUCCESS")
else:
print(f" ❌ Both OpenCL and CPU transitions failed - using original clip")
transition_clips.append(curr_clip)
else:
print(f" ❌ {transition_type.upper()} transition {j} FAILED - using original clip")
transition_clips.append(curr_clip)

if len(transition_clips) == 1:
os.rename(transition_clips[0], chunk_file)
print(f" ✨ Using single-command image-to-image transitions")

# Create a single FFmpeg command that loads all images and applies transitions
# This is the correct approach for slideshow transitions

# Build inputs and filter graph
inputs = []
filter_parts = []

for i, clip in enumerate(temp_clips):
inputs.append(f'-i "{clip}"')

# Get all clip durations
from .utils import get_audio_duration
clip_durations = [get_audio_duration(clip) for clip in temp_clips]
total_duration = sum(clip_durations)

# Use simpler approach: concat with transition filter
# This avoids complex filter graph chaining issues
concat_file = f"{temp_dir}/transition_concat_{chunk_idx}.txt"
with open(concat_file, 'w') as f:
for clip in temp_clips:
f.write(f"file '{os.path.abspath(clip)}'\n")

# Choose one transition type for the whole slideshow
candidates = available_transitions[:]
random.shuffle(candidates)
transition_type = 'fade' # fallback
for cand in candidates:
test_cmd = f'ffmpeg -v error -f lavfi -i "color=red:size=320x240:duration=2" -f lavfi -i "color=blue:size=320x240:duration=2" -filter_complex "[0:v][1:v]xfade=transition={cand}:duration=1.0:offset=1.0" -t 1 -f null -'
if run_command(test_cmd, f" Probe transition {cand}", show_output=False):
transition_type = cand
break

# Use the concat approach that works reliably
# Future enhancement: implement proper transition filter chains
encoding_params = get_encoding_params(nvenc_available, fps)
cmd = f'ffmpeg -y -f concat -safe 0 -i "{concat_file}" {encoding_params} "{chunk_file}"'

print(f" πŸ”„ Concat slideshow command: {cmd}")
if run_command(cmd, f" Creating slideshow", show_output=False):
print(f" βœ… Slideshow creation SUCCESS")
else:
concat_file = f"{temp_dir}/final_concat_{chunk_idx}.txt"
with open(concat_file, 'w') as f:
for clip in transition_clips:
f.write(f"file '{os.path.abspath(clip)}'\n")
cmd = f'ffmpeg -y -f concat -safe 0 -i "{concat_file}" -c:v libx264 -c:a aac -r {fps} -crf {DEFAULT_CRF} -preset {DEFAULT_PRESET} "{chunk_file}"'
if not run_command(cmd, f" Finalizing chunk {chunk_idx + 1} (re-encoding to preserve transitions)", show_output=False):
return False
for clip in transition_clips[1:]:
try:
os.remove(clip)
except:
pass
os.remove(concat_file)
print(f" ❌ Slideshow creation failed")
return False

for clip in temp_clips:
try:
Expand Down
Loading