Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure video stream is laid out first #660

Merged
merged 1 commit into from
Feb 23, 2025
Merged
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
6 changes: 6 additions & 0 deletions auto_editor/cmds/test.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
from time import perf_counter
from typing import TYPE_CHECKING

import av
import numpy as np

from auto_editor.ffwrapper import FileInfo, initFileInfo
@@ -235,6 +236,11 @@ def desc():

def example():
out = run.main(inputs=["example.mp4"], cmd=[])

with av.open(out) as container:
assert container.streams[0].type == "video"
assert container.streams[1].type == "audio"

cn = fileinfo(out)
video = cn.videos[0]

36 changes: 18 additions & 18 deletions auto_editor/edit.py
Original file line number Diff line number Diff line change
@@ -309,6 +309,13 @@ def make_media(tl: v3, output_path: str) -> None:
else:
audio_paths = []

# Setup video
if ctr.default_vid != "none" and tl.v:
vframes = render_av(output, tl, args, log)
output_stream = next(vframes)
else:
output_stream, vframes = None, iter([])

# Setup audio
if audio_paths:
try:
@@ -363,13 +370,6 @@ def make_media(tl: v3, output_path: str) -> None:
subtitle_streams.append(subtitle_stream)
sub_gen_frames.append(subtitle_input.demux(subtitles=0))

# Setup video
if ctr.default_vid != "none" and tl.v:
vframes = render_av(output, tl, args, log)
output_stream = next(vframes)
else:
output_stream, vframes = None, iter([])

no_color = log.no_color or log.machine
encoder_titles = []
if output_stream is not None:
@@ -401,17 +401,6 @@ def make_media(tl: v3, output_path: str) -> None:
):
break

for audio_stream, audio_frame in zip(audio_streams, audio_frames):
if audio_frame:
for reframe in resampler.resample(audio_frame):
output.mux(audio_stream.encode(reframe))

for subtitle_stream, packet in zip(subtitle_streams, subtitle_frames):
if not packet or packet.dts is None:
continue
packet.stream = subtitle_stream
output.mux(packet)

if video_frame:
try:
output.mux(output_stream.encode(video_frame))
@@ -423,6 +412,17 @@ def make_media(tl: v3, output_path: str) -> None:
except av.FFmpegError as e:
log.error(e)

for audio_stream, audio_frame in zip(audio_streams, audio_frames):
if audio_frame:
for reframe in resampler.resample(audio_frame):
output.mux(audio_stream.encode(reframe))

for subtitle_stream, packet in zip(subtitle_streams, subtitle_frames):
if not packet or packet.dts is None:
continue
packet.stream = subtitle_stream
output.mux(packet)

bar.tick(index)

# Flush streams