Skip to content

Commit

Permalink
fix some compile bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia committed Jan 11, 2024
1 parent 4729eaf commit 7251b04
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/ffmpeg/nodes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def incoming_streams(self) -> Sequence[OutputStream]:
def get_args(self, context: _DAGContext = empty_dag_context) -> list[str]:
commands = []
for key, value in self.kwargs.items():
commands += [f"-{key}", str(value)]
if isinstance(value, bool) and value is True:
commands += [f"-{key}"]
else:
commands += [f"-{key}", str(value)]
return commands


Expand Down Expand Up @@ -216,7 +219,10 @@ def get_args(self, context: _DAGContext = empty_dag_context) -> list[str]:
commands += ["-map", input.label(context)]

for key, value in self.kwargs.items():
commands += [f"-{key}", str(value)]
if isinstance(value, bool) and value is True:
commands += [f"-{key}"]
else:
commands += [f"-{key}", str(value)]
commands += [self.filename]
return commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"in2.mp4",
"-filter_complex",
"[0:v]hflip[s2];[1:a]areverse[s0];[1:v]reverse[s1];[s0]aphaser[s3];[s1]hue=s=0[s4];[s2][s3][s4][s3]concat=v=1:a=1[s5#0][s5#1];[s5#1]volume=volume=0.8[s6]",
"[0:v]hflip[s1];[1:a]areverse[s2];[1:v]reverse[s0];[s0]hue=s=0[s4];[s1][s3][s4][s3]concat=v=1:a=1[s5#0][s5#1];[s2]aphaser[s3];[s5#1]volume=volume=0.8[s6]",
"-map",
"[s5#0]",
"-map",
Expand Down
2 changes: 1 addition & 1 deletion src/ffmpeg/tests/__snapshots__/test_base/test_compile.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"-i",
"overlay.png",
"-filter_complex",
"[0]trim=start_frame=10:end_frame=20[s0];[0]trim=start_frame=30:end_frame=40[s1];[1]hflip[s2];[s0][s1]concat[s3];[s3][s2]overlay[s4];[s4]drawbox=x=50:y=50:width=120:height=120:color=red:thickness=5[s5]",
"[0]trim=start_frame=10:end_frame=20[s0];[0]trim=start_frame=30:end_frame=40[s2];[1]hflip[s1];[s0][s2]concat[s3];[s3][s1]overlay[s4];[s4]drawbox=x=50:y=50:width=120:height=120:color=red:thickness=5[s5]",
"-map",
"[s5]",
"out.mp4"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
"ffmpeg",
"-y",
"-i",
"input-video.mp4",
"-i",
"audio-left.wav",
"-i",
"audio-right.wav",
"-filter_complex",
"[1]atrim=start=5[s1];[2]atrim=start=10[s0];[s0]asetpts=expr=PTS-STARTPTS[s3];[s1]asetpts=expr=PTS-STARTPTS[s2];[s2][s3]join=inputs=2:channel_layout=stereo:map=[s4]",
"-map",
"[s4]",
"-map",
"[0:v]",
"-shortest",
"-vcodec",
"copy",
"output-video.mp4"
]
44 changes: 37 additions & 7 deletions src/ffmpeg/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from syrupy.extensions.json import JSONSnapshotExtension

from ..base import input, output
from ..filters import concat
from ..filters import concat, join
from ..streams.video import VideoStream


Expand Down Expand Up @@ -117,18 +117,48 @@ def test_audio_video_pipeline(snapshot: SnapshotAssertion) -> None:
v3 = joined.video(0)
a3 = joined.audio(0).volume(volume="0.8")
assert snapshot(extension_class=JSONSnapshotExtension) == output(v3, a3, filename="out.mp4").compile()

# ['ffmpeg',
# '-i',
# 'in1.mp4',
# '-i',
# 'in2.mp4',
# '-filter_complex',
# '[0:v]hflip[s0];[1:v]reverse[s1];[s1]hue=s=0[s2];[1:a]areverse[s3];[s3]aphaser[s4];[s0][0:a][s2][s4]concat=a=1:n=2:v=1[s5][s6];[s6]volume=0.8[s7]',
# '-map',
# '[s5]',
# '-map',
# '[s7]',
# 'out.mp4']


def test_mono_to_stereo_with_offsets_and_video(snapshot: SnapshotAssertion) -> None:
audio_left = input("audio-left.wav").atrim(start=5).asetpts(expr="PTS-STARTPTS")
audio_right = input("audio-right.wav").atrim(start=10).asetpts(expr="PTS-STARTPTS")
input_video = input("input-video.mp4")
assert snapshot(extension_class=JSONSnapshotExtension) == (
join(audio_left, audio_right, inputs=2, channel_layout="stereo", map="")
.output(input_video.video, filename="output-video.mp4", shortest=True, vcodec="copy")
.overwrite_output()
.compile()
)


# ['ffmpeg',
# '-i',
# 'in1.mp4',
# 'audio-left.wav',
# '-i',
# 'audio-right.wav',
# '-i',
# 'in2.mp4',
# 'input-video.mp4',
# '-filter_complex',
# '[0:v]hflip[s0];[1:v]reverse[s1];[s1]hue=s=0[s2];[1:a]areverse[s3];[s3]aphaser[s4];[s0][0:a][s2][s4]concat=a=1:n=2:v=1[s5][s6];[s6]volume=0.8[s7]',
# '[0]atrim=start=5[s0];[s0]asetpts=PTS-STARTPTS[s1];[1]atrim=start=10[s2];[s2]asetpts=PTS-STARTPTS[s3];[s1][s3]join=channel_layout=stereo:inputs=2[s4]',
# '-map',
# '[s5]',
# '[s4]',
# '-map',
# '[s7]',
# 'out.mp4']
# '2:v',
# '-shortest',
# '-vcodec',
# 'copy',
# 'output-video.mp4',
# '-y']

0 comments on commit 7251b04

Please sign in to comment.