summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Kocialkowski2022-10-28 15:39:48 +0200
committerPaul Kocialkowski2022-10-28 17:58:42 +0200
commita8360c30c7be213ab4b90dcf1134be6574065b0c (patch)
tree0efe71bbc261de2fb1eb0b852e6519b5d4c64c9a
parent54399b6bf0810f4d3eab6aa8fc17df1f835b6de3 (diff)
capture-pipeline: Improve settings management
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rwxr-xr-xcapture-pipeline122
1 files changed, 78 insertions, 44 deletions
diff --git a/capture-pipeline b/capture-pipeline
index 0c85e85..1a8ecde 100755
--- a/capture-pipeline
+++ b/capture-pipeline
@@ -9,8 +9,8 @@ import yaml
# utils
-def selection_skip(element):
- if "selection" in element and element["selection"] == "skip":
+def selection_skip(item):
+ if "selection" in item and item["selection"] == "skip":
return True
return False
@@ -19,16 +19,20 @@ def selection_skip(element):
settings = {}
-def settings_entry(shot, entry):
+def settings_entry(entry):
global settings
- if entry in shot:
- return shot[entry]
- elif entry in settings:
+ if entry in settings:
return settings[entry]
else:
return None
+def settings_item_entry(item, entry):
+ if entry in item:
+ return item[entry]
+ else:
+ return settings_entry(entry)
+
# timecode
def timecode_seconds(timecode):
@@ -174,33 +178,42 @@ def audio_ffmpeg_command(sequence, shot, take, part):
ffmpeg_command = [ "ffmpeg" ]
- if "audio-start" in part:
- ffmpeg_command += [ "-ss", part["audio-start"] ]
- elif "video-start" in part:
- video_start_seconds = timecode_seconds(part["video-start"])
- video_sync_seconds = timecode_seconds(take["video-sync"])
- audio_sync_seconds = timecode_seconds(take["audio-sync"])
+ audio_sync = settings_item_entry(take, "audio-sync")
+ video_sync = settings_item_entry(take, "video-sync")
+
+ audio_start = settings_item_entry(shot, "audio-start") or settings_item_entry(part, "audio-start")
+ video_start = settings_item_entry(shot, "video-start") or settings_item_entry(part, "video-start")
+
+ if audio_start:
+ ffmpeg_command += [ "-ss", audio_start ]
+ elif video_start:
+ video_start_seconds = timecode_seconds(video_start)
+ video_sync_seconds = timecode_seconds(video_sync)
+ audio_sync_seconds = timecode_seconds(audio_sync)
audio_start_seconds = audio_sync_seconds + video_start_seconds - video_sync_seconds
ffmpeg_command += [ "-ss", timecode_string(audio_start_seconds) ]
- if "audio-stop" in part:
- ffmpeg_command += [ "-to", part["audio-stop"] ]
- elif "video-stop" in part:
- video_stop_seconds = timecode_seconds(part["video-stop"])
- video_sync_seconds = timecode_seconds(take["video-sync"])
- audio_sync_seconds = timecode_seconds(take["audio-sync"])
+ audio_stop = settings_item_entry(shot, "audio-stop") or settings_item_entry(part, "audio-stop")
+ video_stop = settings_item_entry(shot, "video-stop") or settings_item_entry(part, "video-stop")
+
+ if audio_stop:
+ ffmpeg_command += [ "-to", audio_stop ]
+ elif video_stop:
+ video_stop_seconds = timecode_seconds(video_stop)
+ video_sync_seconds = timecode_seconds(video_sync)
+ audio_sync_seconds = timecode_seconds(audio_sync)
audio_stop_seconds = audio_sync_seconds + video_stop_seconds - video_sync_seconds
ffmpeg_command += [ "-to", timecode_string(audio_stop_seconds) ]
ffmpeg_command += [ "-i", source_path ]
- encoder = settings_entry(shot, "audio-encoder")
+ encoder = settings_item_entry(shot, "audio-encoder")
if encoder:
ffmpeg_command += [ "-c:a", encoder ]
- filters = settings_entry(shot, "audio-filters")
+ filters = settings_item_entry(shot, "audio-filters")
if filters:
ffmpeg_command += [ "-filter:a", ",".join(filters) ]
@@ -243,10 +256,10 @@ def audio_process(sequence, shot, take, part):
# video
def video_suffix(shot):
- return "." + settings_entry(shot, "video-extension")
+ return "." + settings_item_entry(shot, "video-extension")
def video_source_base(sequence, shot):
- return os.path.join(settings_entry(shot, "video-source"), sequence["label"])
+ return os.path.join(settings_item_entry(shot, "video-source"), sequence["label"])
def video_source_name(sequence, shot, take):
base = video_source_base(sequence, shot)
@@ -283,7 +296,7 @@ def video_output_name(sequence, shot, take, part = None):
label = shot_label(shot)
prefix = shot_prefix(shot)
suffix = video_suffix(shot)
- name = ""
+ name = prefix
if part and "actions" in part:
actions = part["actions"]
@@ -291,18 +304,21 @@ def video_output_name(sequence, shot, take, part = None):
if len(actions) > 4:
actions = actions[:2] + actions[-2:]
+ if name:
+ name += "-"
+ else:
+ name = ""
+
for action in actions:
name += action + "-"
- # remove separator
+ # Remove final separator.
name = name[:-1]
elif label:
- name = label
- else:
- return None
-
- if prefix:
- name += "-" + prefix
+ if name:
+ name += "-"
+ else:
+ name = label
return name
@@ -339,49 +355,63 @@ def video_output_prepare(sequence):
def video_ffmpeg_command(sequence, shot, take, part):
source_path = video_source_path(sequence, shot, take)
output_path = video_output_path(sequence, shot, take, part)
+ early_cut_safe = True
ffmpeg_command = [ "ffmpeg" ]
- if "video-start" in part:
- ffmpeg_command += [ "-ss", part["video-start"] ]
+ encoder = settings_item_entry(shot, "video-encoder")
- if "video-stop" in part:
- ffmpeg_command += [ "-to", part["video-stop"] ]
+ # Encoding is needed to cut at arbitrary positions, otherwise we
+ # might miss reference frames in the bitstream.
+ if encoder and encoder == "copy":
+ early_cut_safe = False
- ffmpeg_command += [ "-i", source_path ]
+ if not early_cut_safe:
+ ffmpeg_command += [ "-i", source_path ]
- width = settings_entry(shot, "video-width")
- height = settings_entry(shot, "video-height")
+ video_start = settings_item_entry(shot, "video-start")or settings_item_entry(part, "video-start")
+ if video_start:
+ ffmpeg_command += [ "-ss", video_start ]
+
+ video_stop = settings_item_entry(shot, "video-stop") or settings_item_entry(part, "video-stop")
+ if video_stop:
+ ffmpeg_command += [ "-to", video_stop ]
+
+ if early_cut_safe:
+ ffmpeg_command += [ "-i", source_path ]
+
+ width = settings_item_entry(shot, "video-width")
+ height = settings_item_entry(shot, "video-height")
if width and height:
ffmpeg_command += [ "-s", str(width)+"x"+str(height) ]
- frame_rate = settings_entry(shot, "video-frame-rate")
+ frame_rate = settings_item_entry(shot, "video-frame-rate")
if frame_rate:
ffmpeg_command += [ "-r", str(frame_rate) ]
- encoder = settings_entry(shot, "video-encoder")
+ encoder = settings_item_entry(shot, "video-encoder")
if encoder:
ffmpeg_command += [ "-c:v", encoder ]
- crf = settings_entry(shot, "video-crf")
+ crf = settings_item_entry(shot, "video-crf")
if crf:
ffmpeg_command += [ "-crf", str(crf) ]
- quality = settings_entry(shot, "video-quality")
+ quality = settings_item_entry(shot, "video-quality")
if quality:
ffmpeg_command += [ "-q:v", str(quality) ]
- rate_max = settings_entry(shot, "video-rate-max")
+ rate_max = settings_item_entry(shot, "video-rate-max")
if rate_max:
ffmpeg_command += [ "-maxrate", rate_max ]
ffmpeg_command += [ "-bufsize", "2M" ]
- filters = settings_entry(shot, "video-filters")
+ filters = settings_item_entry(shot, "video-filters")
if filters:
ffmpeg_command += [ "-filter:v", ",".join(filters) ]
- audio = settings_entry(shot, "video-audio")
+ audio = settings_item_entry(shot, "video-audio")
if audio == "remove":
ffmpeg_command += [ "-an" ]
@@ -471,6 +501,10 @@ def shot_prefix(shot):
label += separator + shot["position"]
separator = "-"
+ if "subject" in shot:
+ label += separator + shot["subject"]
+ separator = "-"
+
return label
def shot_label(shot):