Vectorize generic metadata video updates

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Tavish
2026-06-22 11:12:41 +08:00
parent 1c31debaa1
commit a3837d9e16
+40 -19
View File
@@ -446,30 +446,51 @@ def _update_meta_data_without_fragmenting(df, dst_meta, meta_idx, data_idx, vide
src_to_offset = video_idx.get("src_to_offset", {}) src_to_offset = video_idx.get("src_to_offset", {})
src_to_dst = video_idx.get("src_to_dst", {}) src_to_dst = video_idx.get("src_to_dst", {})
row_index = pd.MultiIndex.from_arrays(
[orig_chunks, orig_files],
names=["chunk_index", "file_index"],
)
if src_to_dst: if src_to_dst:
for idx, orig_chunk, orig_file in zip( src_keys = list(src_to_dst)
df.index, orig_chunks, orig_files, strict=False mapping_index = pd.MultiIndex.from_tuples(
): src_keys,
src_key = (orig_chunk, orig_file) names=["chunk_index", "file_index"],
dst_chunk, dst_file = src_to_dst.get( )
src_key, (video_idx["chunk"], video_idx["file"]) mapping_df = pd.DataFrame(
) [
df.at[idx, orig_chunk_col] = dst_chunk (
df.at[idx, orig_file_col] = dst_file *src_to_dst[src_key],
src_to_offset.get(src_key, 0.0),
offset = src_to_offset.get(src_key, 0) )
df.at[idx, f"videos/{key}/from_timestamp"] += offset for src_key in src_keys
df.at[idx, f"videos/{key}/to_timestamp"] += offset ],
index=mapping_index,
columns=["dst_chunk", "dst_file", "offset"],
)
reindexed = mapping_df.reindex(row_index)
df[orig_chunk_col] = (
reindexed["dst_chunk"]
.fillna(video_idx["chunk"])
.astype(orig_chunks.dtype, copy=False)
.to_numpy()
)
df[orig_file_col] = (
reindexed["dst_file"]
.fillna(video_idx["file"])
.astype(orig_files.dtype, copy=False)
.to_numpy()
)
offsets = reindexed["offset"].fillna(0.0).to_numpy(dtype=float)
df[f"videos/{key}/from_timestamp"] += offsets
df[f"videos/{key}/to_timestamp"] += offsets
elif src_to_offset: elif src_to_offset:
df[orig_chunk_col] = video_idx["chunk"] df[orig_chunk_col] = video_idx["chunk"]
df[orig_file_col] = video_idx["file"] df[orig_file_col] = video_idx["file"]
for idx, orig_chunk, orig_file in zip( mapping_series = pd.Series(src_to_offset, dtype=float)
df.index, orig_chunks, orig_files, strict=False offsets = mapping_series.reindex(row_index).fillna(0.0).to_numpy()
): df[f"videos/{key}/from_timestamp"] += offsets
offset = src_to_offset.get((orig_chunk, orig_file), 0) df[f"videos/{key}/to_timestamp"] += offsets
df.at[idx, f"videos/{key}/from_timestamp"] += offset
df.at[idx, f"videos/{key}/to_timestamp"] += offset
else: else:
df[orig_chunk_col] = video_idx["chunk"] df[orig_chunk_col] = video_idx["chunk"]
df[orig_file_col] = video_idx["file"] df[orig_file_col] = video_idx["file"]