2026-01-22 12:24:32 +01:00
|
|
|
import os
|
2026-01-29 12:11:30 +01:00
|
|
|
import shutil
|
2026-01-22 12:24:32 +01:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
import ox
|
|
|
|
|
|
|
|
|
|
import itemlist.models
|
|
|
|
|
import item.models
|
|
|
|
|
|
|
|
|
|
from .render_kdenlive import KDEnliveProject, _CACHE
|
|
|
|
|
from .render import default_prefix as root
|
2026-01-24 13:26:30 +01:00
|
|
|
from .render import load_defaults
|
|
|
|
|
|
|
|
|
|
def render_all(options):
|
2026-01-29 12:11:30 +01:00
|
|
|
if not options["force"] and os.path.exists(os.path.join(root, "render/forest-5.1.mp4")):
|
2026-01-24 13:26:30 +01:00
|
|
|
print("forest-5.1.mp4 exists, skipping")
|
|
|
|
|
else:
|
|
|
|
|
render_forest()
|
2026-01-29 12:11:30 +01:00
|
|
|
if not options["force"] and os.path.exists(os.path.join(root, "render/music-5.1.mp4")):
|
2026-01-24 13:26:30 +01:00
|
|
|
print("music-5.1.mp4 exists, skipping")
|
|
|
|
|
else:
|
|
|
|
|
render_music()
|
2026-01-22 12:24:32 +01:00
|
|
|
|
|
|
|
|
def render_music():
|
2026-01-24 13:26:30 +01:00
|
|
|
# Stereo Mix, playing on 5.1 front left/right
|
|
|
|
|
project = KDEnliveProject(root)
|
|
|
|
|
qs = item.models.Item.objects.filter(
|
|
|
|
|
data__type__icontains='music'
|
|
|
|
|
).order_by('sort__title')
|
|
|
|
|
|
|
|
|
|
for clip in qs:
|
|
|
|
|
src = clip.files.all()[0].data.path
|
|
|
|
|
project.append_clip('A1', {
|
|
|
|
|
"src": src,
|
|
|
|
|
"duration": clip.sort.duration,
|
|
|
|
|
"filter": {
|
2026-01-30 14:28:33 +01:00
|
|
|
'volume': '0',
|
2026-01-24 13:26:30 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
path = os.path.join(root, "music.kdenlive")
|
|
|
|
|
with open(path, 'w') as fd:
|
|
|
|
|
fd.write(project.to_xml())
|
|
|
|
|
|
|
|
|
|
os.chdir(root)
|
|
|
|
|
cmd = [
|
|
|
|
|
"melt", "music.kdenlive", '-quiet', '-consumer', 'avformat:music.wav'
|
|
|
|
|
]
|
|
|
|
|
print(" ".join([str(x) for x in cmd]))
|
|
|
|
|
subprocess.call(cmd)
|
|
|
|
|
info = ox.avinfo('music.wav')
|
|
|
|
|
cmds = []
|
|
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
|
|
|
|
"-f", "lavfi", "-i", "anullsrc=r=48000:cl=mono",
|
|
|
|
|
"-t", str(info["duration"]),
|
|
|
|
|
"music_silence.wav"
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
for src, out1, out2 in (
|
|
|
|
|
('music.wav', "music_left.wav", "music_right.wav"),
|
|
|
|
|
):
|
|
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
|
|
|
|
"-i", src,
|
|
|
|
|
"-filter_complex",
|
|
|
|
|
"[0:0]pan=1|c0=c0[left]; [0:0]pan=1|c0=c1[right]",
|
|
|
|
|
"-map", "[left]", out1,
|
|
|
|
|
"-map", "[right]", out2,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
|
|
|
|
"-i", "music_left.wav",
|
|
|
|
|
"-i", "music_right.wav",
|
|
|
|
|
"-i", "music_silence.wav",
|
|
|
|
|
"-i", "music_silence.wav",
|
|
|
|
|
"-i", "music_silence.wav",
|
|
|
|
|
"-i", "music_silence.wav",
|
|
|
|
|
"-filter_complex", "[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6[a]",
|
|
|
|
|
"-map", "[a]",
|
|
|
|
|
"-ar", "48000",
|
2026-01-29 12:11:30 +01:00
|
|
|
"-c:a", "aac", "render/music-5.1-new.mp4"
|
2026-01-24 13:26:30 +01:00
|
|
|
])
|
|
|
|
|
for cmd in cmds:
|
|
|
|
|
print(" ".join([str(x) for x in cmd]))
|
|
|
|
|
subprocess.call(cmd)
|
2026-01-29 12:11:30 +01:00
|
|
|
shutil.move("render/music-5.1-new.mp4", "render/music-5.1.mp4")
|
2026-01-24 13:26:30 +01:00
|
|
|
for name in (
|
|
|
|
|
"music.kdenlive",
|
|
|
|
|
"music.wav",
|
|
|
|
|
"music_left.wav",
|
|
|
|
|
"music_right.wav",
|
|
|
|
|
"music_silence.wav",
|
|
|
|
|
):
|
|
|
|
|
if os.path.exists(name):
|
|
|
|
|
os.unlink(name)
|
2026-01-22 12:24:32 +01:00
|
|
|
|
|
|
|
|
def render_forest():
|
|
|
|
|
# Stereo Mix, playing on 5.1 rear left/right
|
|
|
|
|
project = KDEnliveProject(root)
|
|
|
|
|
qs = item.models.Item.objects.filter(
|
|
|
|
|
data__type__icontains='Forest'
|
|
|
|
|
).order_by('sort__title')
|
|
|
|
|
|
|
|
|
|
for clip in qs:
|
|
|
|
|
src = clip.files.all()[0].data.path
|
|
|
|
|
project.append_clip('A1', {
|
|
|
|
|
"src": src,
|
|
|
|
|
"duration": clip.sort.duration,
|
|
|
|
|
"filter": {
|
2026-01-30 14:28:33 +01:00
|
|
|
'volume': '0',
|
2026-01-22 12:24:32 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
path = os.path.join(root, "forest.kdenlive")
|
|
|
|
|
with open(path, 'w') as fd:
|
|
|
|
|
fd.write(project.to_xml())
|
|
|
|
|
|
2026-01-24 13:26:30 +01:00
|
|
|
os.chdir(root)
|
|
|
|
|
cmd = [
|
2026-01-22 12:24:32 +01:00
|
|
|
"melt", "forest.kdenlive", '-quiet', '-consumer', 'avformat:forest.wav'
|
2026-01-24 13:26:30 +01:00
|
|
|
]
|
|
|
|
|
print(" ".join([str(x) for x in cmd]))
|
|
|
|
|
subprocess.call(cmd)
|
2026-01-22 12:24:32 +01:00
|
|
|
info = ox.avinfo('forest.wav')
|
2026-01-24 13:26:30 +01:00
|
|
|
cmds = []
|
2026-01-22 12:24:32 +01:00
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
|
|
|
|
"-f", "lavfi", "-i", "anullsrc=r=48000:cl=mono",
|
|
|
|
|
"-t", str(info["duration"]),
|
|
|
|
|
"forest_silence.wav"
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
for src, out1, out2 in (
|
|
|
|
|
('forest.wav', "forest_left.wav", "forest_right.wav"),
|
|
|
|
|
):
|
|
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
|
|
|
|
"-i", src,
|
|
|
|
|
"-filter_complex",
|
|
|
|
|
"[0:0]pan=1|c0=c0[left]; [0:0]pan=1|c0=c1[right]",
|
|
|
|
|
"-map", "[left]", out1,
|
|
|
|
|
"-map", "[right]", out2,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
cmds.append([
|
|
|
|
|
"ffmpeg", "-y",
|
|
|
|
|
"-nostats", "-loglevel", "error",
|
2026-01-24 13:26:30 +01:00
|
|
|
"-i", "forest_silence.wav",
|
|
|
|
|
"-i", "forest_silence.wav",
|
|
|
|
|
"-i", "forest_silence.wav",
|
|
|
|
|
"-i", "forest_silence.wav",
|
2026-01-22 12:24:32 +01:00
|
|
|
"-i", "forest_left.wav",
|
|
|
|
|
"-i", "forest_right.wav",
|
|
|
|
|
"-filter_complex", "[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6[a]",
|
|
|
|
|
"-map", "[a]",
|
|
|
|
|
"-ar", "48000",
|
2026-01-29 12:11:30 +01:00
|
|
|
"-c:a", "aac", "render/forest-5.1-new.mp4"
|
2026-01-22 12:24:32 +01:00
|
|
|
])
|
|
|
|
|
for cmd in cmds:
|
|
|
|
|
print(" ".join([str(x) for x in cmd]))
|
|
|
|
|
subprocess.call(cmd)
|
2026-01-29 12:11:30 +01:00
|
|
|
shutil.move("render/forest-5.1-new.mp4", "render/forest-5.1.mp4")
|
2026-01-22 12:24:32 +01:00
|
|
|
for name in (
|
2026-01-24 13:26:30 +01:00
|
|
|
"forest.kdenlive",
|
2026-01-22 12:24:32 +01:00
|
|
|
"forest.wav",
|
|
|
|
|
"forest_left.wav",
|
|
|
|
|
"forest_right.wav",
|
2026-01-24 13:26:30 +01:00
|
|
|
"forest_silence.wav",
|
2026-01-22 12:24:32 +01:00
|
|
|
):
|
|
|
|
|
if os.path.exists(name):
|
|
|
|
|
os.unlink(name)
|