동영상 특정 영역 모자이크(흐리게) 하기

준비물: python, ffmpeg

동영상 파일을 input.mp4 로 복사 또는 수정한다.
아래 파이썬 코드를 이용하여 흐리게 할 영역 및 시간을 구한다.

import cv2

video_path = "input.mp4"
cap = cv2.VideoCapture(video_path)

frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fps = cap.get(cv2.CAP_PROP_FPS)

cv2.namedWindow("Video Viewer")

roi_start = None
roi_end = None
dragging = False
current_frame = None

def draw_rectangle(event, x, y, flags, param):
    global roi_start, roi_end, dragging
    if event == cv2.EVENT_LBUTTONDOWN:
        roi_start = (x, y)
        dragging = True
    elif event == cv2.EVENT_MOUSEMOVE and dragging:
        roi_end = (x, y)
        redraw_frame()
    elif event == cv2.EVENT_LBUTTONUP:
        roi_end = (x, y)
        dragging = False
        x0, y0 = roi_start
        x1, y1 = roi_end
        x, y = min(x0, x1), min(y0, y1)
        w, h = abs(x1 - x0), abs(y1 - y0)

        if w > 0 and h > 0:
            print(f"{w}:{h}:{x}:{y}")

        redraw_frame()

def redraw_frame():
    if current_frame is None:
        return
    frame = current_frame.copy()
    if roi_start and roi_end:
        x0, y0 = roi_start
        x1, y1 = roi_end
        w = abs(x1 - x0)
        h = abs(y1 - y0)
        if w > 0 and h > 0:
            cv2.rectangle(frame, roi_start, roi_end, (255, 0, 0), 2)
    frame_number = cv2.getTrackbarPos("Frame", "Video Viewer")
    time_text = f"Time: {frame_number / fps:.2f}s"
    cv2.putText(frame, time_text, (10, 30),
                cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
    cv2.imshow("Video Viewer", frame)

def on_trackbar(val):
    global current_frame
    cap.set(cv2.CAP_PROP_POS_FRAMES, val)
    ret, frame = cap.read()
    if ret:
        current_frame = frame.copy()
        redraw_frame()

cv2.setMouseCallback("Video Viewer", draw_rectangle)
cv2.createTrackbar("Frame", "Video Viewer", 0, frame_count - 1, on_trackbar)

# 초기 프레임 표시
on_trackbar(0)

while True:
    if cv2.getWindowProperty("Video Viewer", cv2.WND_PROP_VISIBLE) < 1:
        break
    key = cv2.waitKey(100)
    if key == 27:
        break

cap.release()
cv2.destroyAllWindows()

그리고 ffmpeg.exe 을 이용하여 아래와 같이 사용한다.
영역값은 드래그 했을때 출력된 값 (예: 100:100:40:80)
시작시간,종료시간은 초단위 (예: 3.5)

ffmpeg -y -i input.mp4 -filter_complex "[0:v]crop={영역값},boxblur=3:1[blur]; [0:v][blur]overlay=43:65:enable='between(t,{시작시간},{종료시간})'" -c:a copy output.mp4

评论

精华帖

Delphi TDirectory.Delete 대신 CMD 으로 폴더 삭제
Windows Chrome 및 Edge를 TLS 1.2 모드로 실행
开发技巧 애드센스 자동 광고 사용 시 빈 화면이 출력된다면?
Windows 브라우저 환경설정 추출
WordPress xmlrpc.php 차단으로 보안 강화하기
Delphi 폼이 모니터 한 가운데 있는 경우 자연스럽게 왼쪽으로 …
Windows WSH script registration is not valid.
WordPress 제목 블록 기본값을 H5로 변경하는 방법
浏览 Python 동영상 특정 영역 모자이크(흐리게) 하기
Linux 구글 크롬 콘솔 'Attestation check for Topics on' 에…
其他 크롬 - 개발자 도구(DevTools)에서 붙여넣기 안될때
GnuBoard SmartEditor2Skin.html 다운로드 되는 현상
Windows 네트워크 탐지
Delphi TrayIcon 이 흐릿하게 보이는 버그? 수정
Delphi 실행 중인 프로세스가 활성 창인지 확인하는 함수
Delphi 메세지 다이어그램(Message Dialog) 에 체크박스(CheckB…
GnuBoard 부트스트랩 테마 예제로 사용중인 main.php
GnuBoard 유튜브 스킨
Windows TLS 연결 끊김 해결 방법 - Kyber 비활성화
开发技巧 검색 로봇 접속시 종료
Windows WinDivert 사용중인 어플리케이션 검색
WordPress 답글 남기기 메시지 변경
Linux PHP-FPM 튜닝을 위한 메모리 계산
Windows 아이폰 벨소리 쉽게 추가하기
Windows C:\Windows\Installer 폴더 다른 드라이브로 옮기기
Windows 작업 표시줄 (기타 시스템 트레이 아이콘) 제거 프로그…
WordPress cdn.jsdelivr.net 에서 ssl 인증서 오류 문제
GnuBoard cdn.jsdelivr.net 에서 ssl 인증서 오류 문제
开发技巧 REQUEST 값 받기(application/json 포함)
Linux 데몬(systemd service) 작성 및 실행하기