feat(clips): borrar la metadata heredada del source en los clips finales
Los clips arrastraban el handler de stream "ISO Media file produced by Google Inc." del vídeo original de YouTube: ffmpeg copia la metadata del input por defecto, así que sobrevivía a todos los reencodes y acababa publicado en la red social. Rastro innecesario del origen. Se añade METADATA_SCRUB en ffmpeg_utils y se aplica en cada productor de fichero final: el concat de reframe_v2 (el camino real de prod), el merge de process_video_to_vertical, el passthrough horizontal, el watermark, y los reencodes de subtítulos/hooks/editor. Detalle que costó verificar: -map_metadata -1 global NO basta — el handler_name a nivel de stream sobrevive a un -c copy. Hacen falta los especificadores por stream (-map_metadata:s:v -1 -map_metadata:s:a -1); son inofensivos cuando falta un stream. Verificado con ffprobe sobre un clip real del pipeline completo: sin rastro de Google. No promete boost de alcance (eso lo decide el fingerprint de contenido, no los tags del fichero); es higiene y quitar el rastro del origen.
This commit is contained in:
parent
be4510aa43
commit
6ea46ca5d2
7 changed files with 44 additions and 11 deletions
|
|
@ -9,7 +9,7 @@ from google.genai import types
|
|||
from pydantic import BaseModel
|
||||
|
||||
from edit_builder import build_filter_string
|
||||
from ffmpeg_utils import video_encode_args, QUALITY
|
||||
from ffmpeg_utils import video_encode_args, QUALITY, METADATA_SCRUB
|
||||
|
||||
|
||||
class EditDecision(BaseModel):
|
||||
|
|
@ -405,7 +405,8 @@ class VideoEditor:
|
|||
if not filter_data or not filter_data.get("filter_string"):
|
||||
print("⚠️ No filter string found. Copying original.")
|
||||
try:
|
||||
subprocess.run(['ffmpeg', '-y', '-i', input_path, '-c', 'copy', output_path], timeout=1800)
|
||||
subprocess.run(['ffmpeg', '-y', '-i', input_path, '-c', 'copy',
|
||||
*METADATA_SCRUB, output_path], timeout=1800)
|
||||
except subprocess.TimeoutExpired:
|
||||
raise RuntimeError("FFmpeg copy timed out after 1800s.")
|
||||
return
|
||||
|
|
@ -474,6 +475,7 @@ class VideoEditor:
|
|||
'-vf', filter_string,
|
||||
*video_encode_args(QUALITY),
|
||||
'-c:a', 'copy',
|
||||
*METADATA_SCRUB,
|
||||
'-movflags', '+faststart',
|
||||
output_path
|
||||
]
|
||||
|
|
|
|||
|
|
@ -42,6 +42,18 @@ _NVENC_ARGS = {
|
|||
"-pix_fmt", "yuv420p"],
|
||||
}
|
||||
|
||||
# Output args that drop container/stream metadata carried over from the source
|
||||
# — most notably YouTube's "produced by Google Inc." stream handler, which
|
||||
# otherwise survives every re-encode (ffmpeg copies input metadata by default)
|
||||
# and rides into the published clip. The per-stream specifiers are required:
|
||||
# global -map_metadata -1 alone leaves the audio handler_name intact on a
|
||||
# stream copy. Empty audio/video specifiers are harmless when a clip lacks that
|
||||
# stream (ffmpeg ignores them, verified). Spliced in before the output filename
|
||||
# at each final-artifact producer; kept out of video_encode_args() so that
|
||||
# stays purely codec/quality args.
|
||||
METADATA_SCRUB = ["-map_metadata", "-1", "-map_chapters", "-1",
|
||||
"-map_metadata:s:v", "-1", "-map_metadata:s:a", "-1"]
|
||||
|
||||
_probe_lock = threading.Lock()
|
||||
_nvenc_ok = None # None = not probed yet
|
||||
_announced = False
|
||||
|
|
|
|||
3
hooks.py
3
hooks.py
|
|
@ -6,7 +6,7 @@ import urllib.request
|
|||
import uuid
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||
|
||||
from ffmpeg_utils import video_encode_args, QUALITY
|
||||
from ffmpeg_utils import video_encode_args, QUALITY, METADATA_SCRUB
|
||||
|
||||
FONT_URL = "https://github.com/googlefonts/noto-fonts/raw/main/hinted/ttf/NotoSerif/NotoSerif-Bold.ttf"
|
||||
FONT_DIR = "fonts"
|
||||
|
|
@ -366,6 +366,7 @@ def add_hook_to_video(video_path, text, output_path, position="top", font_scale=
|
|||
+ (f":enable='between(t,0,{float(duration)})'" if duration else ""),
|
||||
'-c:a', 'copy',
|
||||
*video_encode_args(QUALITY),
|
||||
*METADATA_SCRUB,
|
||||
'-movflags', '+faststart',
|
||||
output_path
|
||||
]
|
||||
|
|
|
|||
10
main.py
10
main.py
|
|
@ -22,7 +22,7 @@ from google.genai import types as genai_types
|
|||
|
||||
import gemini_worker
|
||||
from clip_selection import build_transcript_windows, snap_clip_to_words
|
||||
from ffmpeg_utils import video_encode_args, QUALITY, QUALITY_FAST
|
||||
from ffmpeg_utils import video_encode_args, QUALITY, QUALITY_FAST, METADATA_SCRUB
|
||||
from dotenv import load_dotenv
|
||||
import json
|
||||
|
||||
|
|
@ -696,7 +696,7 @@ def finalize_clip_passthrough(input_video, final_output_video):
|
|||
print(f"🎬 Passthrough (native framing): {input_video}")
|
||||
cmd = [
|
||||
'ffmpeg', '-y', '-i', input_video,
|
||||
'-c', 'copy', '-movflags', '+faststart',
|
||||
'-c', 'copy', *METADATA_SCRUB, '-movflags', '+faststart',
|
||||
final_output_video,
|
||||
]
|
||||
subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1800)
|
||||
|
|
@ -764,7 +764,7 @@ def apply_watermark(video_path):
|
|||
tmp_path = video_path + ".wm.mp4"
|
||||
cmd = ["ffmpeg", "-y", "-i", video_path, "-i", logo_path,
|
||||
"-filter_complex", filt,
|
||||
*video_encode_args(QUALITY), "-c:a", "copy",
|
||||
*video_encode_args(QUALITY), "-c:a", "copy", *METADATA_SCRUB,
|
||||
"-movflags", "+faststart", tmp_path]
|
||||
result = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
timeout=1800)
|
||||
|
|
@ -965,12 +965,12 @@ def process_video_to_vertical(input_video, final_output_video, aspect_ratio=ASPE
|
|||
if os.path.exists(temp_audio_output):
|
||||
merge_command = [
|
||||
'ffmpeg', '-y', '-i', temp_video_output, '-i', temp_audio_output,
|
||||
'-c:v', 'copy', '-c:a', 'copy', final_output_video
|
||||
'-c:v', 'copy', '-c:a', 'copy', *METADATA_SCRUB, final_output_video
|
||||
]
|
||||
else:
|
||||
merge_command = [
|
||||
'ffmpeg', '-y', '-i', temp_video_output,
|
||||
'-c:v', 'copy', final_output_video
|
||||
'-c:v', 'copy', *METADATA_SCRUB, final_output_video
|
||||
]
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import os
|
|||
import subprocess
|
||||
import tempfile
|
||||
|
||||
from ffmpeg_utils import video_encode_args, QUALITY_FAST
|
||||
from ffmpeg_utils import video_encode_args, QUALITY_FAST, METADATA_SCRUB
|
||||
|
||||
ANALYSIS_MAX_WIDTH = 640
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ def render(input_video, final_output_video, aspect_ratio):
|
|||
"-f", "concat", "-safe", "0", "-i", list_path,
|
||||
"-i", input_video,
|
||||
"-map", "0:v:0", "-map", "1:a:0?",
|
||||
"-c:v", "copy", "-c:a", "copy",
|
||||
"-c:v", "copy", "-c:a", "copy", *METADATA_SCRUB,
|
||||
final_output_video,
|
||||
])
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import re
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
from ffmpeg_utils import video_encode_args, QUALITY
|
||||
from ffmpeg_utils import video_encode_args, QUALITY, METADATA_SCRUB
|
||||
|
||||
|
||||
_STDIO_CONFIGURED = False
|
||||
|
|
@ -491,6 +491,7 @@ def burn_subtitles(video_path, srt_path, output_path, alignment=2, fontsize=16,
|
|||
'-vf', vf,
|
||||
'-c:a', 'copy',
|
||||
*video_encode_args(QUALITY),
|
||||
*METADATA_SCRUB,
|
||||
'-movflags', '+faststart',
|
||||
output_path
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
import ffmpeg_utils
|
||||
from ffmpeg_utils import (
|
||||
DELIVERY,
|
||||
METADATA_SCRUB,
|
||||
QUALITY,
|
||||
QUALITY_FAST,
|
||||
reset_encoder_cache,
|
||||
|
|
@ -79,3 +80,19 @@ def test_returns_a_fresh_list_each_call():
|
|||
first = video_encode_args(QUALITY)
|
||||
first.append("-mutated")
|
||||
assert "-mutated" not in video_encode_args(QUALITY)
|
||||
|
||||
|
||||
def test_metadata_scrub_covers_global_and_per_stream():
|
||||
# Global -map_metadata -1 alone leaves the audio handler_name intact on a
|
||||
# stream copy — the per-stream specifiers are what strip YouTube's
|
||||
# "produced by Google Inc." handler out of the published clip.
|
||||
assert METADATA_SCRUB[:2] == ["-map_metadata", "-1"]
|
||||
assert "-map_metadata:s:v" in METADATA_SCRUB
|
||||
assert "-map_metadata:s:a" in METADATA_SCRUB
|
||||
|
||||
|
||||
def test_encode_args_stay_free_of_metadata_flags():
|
||||
# The scrub is spliced at call sites, not baked into the codec args — keep
|
||||
# video_encode_args a pure codec/quality list.
|
||||
for tier in (QUALITY, QUALITY_FAST, DELIVERY):
|
||||
assert not any(a.startswith("-map_metadata") for a in video_encode_args(tier))
|
||||
|
|
|
|||
Loading…
Reference in a new issue