Skip to content

PlusMagi's Blog By Pitt Phunsanit

Plus emotional magic to the knowledge of logic.

  • About’s Pitt
Close Button
PlusMagi's Blog By Pitt Phunsanit automation,computer science,Documentation,engineering,macOS,Operating Systems,Python,SecDevOps รวมความยาว video

รวมความยาว video

2020-10-232020-10-23| phunsanitphunsanit| 0 Comment | 10:00
Categories:
  • automation
  • computer science
  • Documentation
  • engineering
  • macOS
  • Operating Systems
  • Python
  • SecDevOps

ากต้องการรวมความยาวของวิดีโอทั้งหมดในโฟลเดอร์ เช่น /Users/Shared/meetings บน macOS คุณสามารถใช้คำสั่งบน Terminal ได้หลายวิธีครับ โดยวิธีที่แม่นยำที่สุดคือการใช้ ffprobe (ซึ่งมาพร้อมกับ ffmpeg) หรือจะใช้คำสั่ง mdls ที่มีอยู่แล้วในเครื่อง macOS ก็ได้ครับ


ใช้ mdls (สะดวกที่สุด ไม่ต้องติดตั้งโปรแกรมเพิ่ม)

macOS มีระบบ Spotlight คอยเก็บ Metadata ของไฟล์อยู่แล้ว สามารถรันคำสั่งนี้บน Terminal เพื่อหาความยาวรวม (วินาที) แล้วแปลงเป็น ชั่วโมง:นาที:วินาที ได้ทันที
find /Users/Shared/meetings -type f ( -name ".mp4" -o -name ".mov" -o -name "*.mkv" ) -print0 | xargs -0 mdls -name kMDItemDurationSeconds | awk '{sum += $3} END {printf "%02d:%02d:%02d\n", sum/3600, (sum%3600)/60, sum%60}'
หมายเหตุ: สามารถเพิ่มหรือลดนามสกุลไฟล์วิดีโอในเครื่องหมาย \( ... \) ได้ตามต้องการ เช่น -name "*.avi"


ใช้ ffprobe (แม่นยำที่สุด สำหรับสาย Dev)

หากในเครื่องมี ffmpeg ติดตั้งอยู่แล้ว (เช่น ติดตั้งผ่าน Homebrew) วิธีนี้จะเช็กจากตัวไฟล์วิดีโอโดยตรงและแม่นยำมากครับ
find /Users/Shared/meetings -type f ( -name ".mp4" -o -name ".mov" -o -name "*.mkv" ) -print0 | xargs -0 -I {} ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "{}" | awk '{sum += $1} END {printf "%02d:%02d:%02d\n", sum/3600, (sum%3600)/60, sum%60}'


ใช้สคริปต์ Python (อ่านง่ายและปรับแต่งต่อสะดวก)

หากต้องการผลลัพธ์ที่ละเอียดขึ้น สามารถสร้างไฟล์สคริปต์ Python สั้น ๆ (ใช้ตัวอ่าน metadata พื้นฐานของ macOS) รันคำสั่งนี้ใน Terminal ได้เลยครับ

python3 -c '
import os, subprocess
total_seconds = 0
path = "/Users/Shared/meetings"
extensions = (".mp4", ".mov", ".mkv", ".avi")

for root, dirs, files in os.walk(path):
    for file in files:
        if file.lower().endswith(extensions):
            filepath = os.path.join(root, file)
            try:
                # ดึงเวลาเป็นวินาทีผ่าน mdls
                output = subprocess.check_output(f"mdls -name kMDItemDurationSeconds \"{filepath}\"", shell=True).decode()
                if "kMDItemDurationSeconds =" in output:
                    sec = float(output.split("=")[1].strip())
                    total_seconds += sec
            except:
                pass

hours = int(total_seconds // 3600)
minutes = int((total_seconds % 3600) // 60)
seconds = int(total_seconds % 60)
print(f"เวลาทั้งหมด: {hours} ชั่วโมง {minutes} นาที {seconds} วินาที (รวม {total_seconds:.2f} วินาที)")
'

อ่านเพิ่มเติม

  • VLC Media Player: ดู video ได้ทุกเรื่อง ทุกไฟล์
  • ดูดโหลด video, MP3 โดย yt-dlp
  • yt-dlp: Options
Tags: avi, Command Line, ffmpeg, ffprobe, macOS, mdls, Metadata, Terminal, Video, video processing

แนะแนวเรื่อง

PREVIOUS Previous post: อีกข้อดีของ jQuery
NEXT Next post: Sci-Fi: Stream Punk

Projects

  • Statement Columns Mapping Helper
  • PlusMagi Blocks
  • PlusMagi Site Search
  • PlusMagi Tags Reindex
  • jQuery Plus Repeater

Recent Posts

  • Apple แต่งตั้ง จอห์น เทอร์นัส (John Ternus) ขึ้นเป็น CEO โดยไม่ใช่ โจนี ไอฟ์ (Jony Ive)
  • Microsoft Coreutils for Windows: เมื่อคำสั่ง Linux ยอดฮิตพร้อมใช้งานแบบ Native บน Windows
  • Browser and profile synchronization (e.g., Firefox, Chrome)
  • Cross-platform connectivity and sharing (KDE Connect, Apache Guacamole, Weylus)
  • Running Windows apps via Virtual Machines (OrbStack, Parallels, UTM) or Wine

Archives

Categories

  • .net core (43)
  • Accounting (1)
  • Action Genre (1)
  • Archaeology (1)
  • art (81)
  • Artificial Intelligence (1)
  • Astronomy (2)
  • Automotive History (1)
  • Bioengineering (1)
  • business (905)
    • Business Analysis (348)
    • Finance (33)
    • Real Estate (27)
  • cd (112)
  • chemistry (1)
  • ci (112)
  • Civil Engineering (2)
  • CMS (30)
  • collaboration (1)
  • Comics (1)
  • Command Line Interface (1)
  • Communication (153)
  • Community Governance (1)
  • Community Management (1)
  • compliance (1)
  • Computer Hardware (59)
  • computer science (1,928)
    • AI (390)
    • Biology (61)
      • Environment (34)
    • Cloud Computing (344)
    • Data Visualization (63)
    • Mathematics (44)
  • container (63)
  • Corporate Governance (3)
  • Corporate Law (1)
  • Cosmology (2)
  • Culture (150)
  • data engineering (1)
  • data management (1)
  • Data Modeling (1)
  • Data Privacy (80)
  • Data Transformation (171)
  • Database Management (2)
  • Design (333)
    • UX/UI (45)
  • development (1)
  • devops (19)
  • Digital Electronics (1)
  • digital marketing (1)
  • e-learning (1)
  • Earth Science (1)
  • Ecology (1)
  • Education (3)
  • Embedded Systems (1)
  • engineering (1,124)
    • architecture (1,004)
    • Building Engineering (99)
  • Entertainment (1)
  • Environmental Science (1)
  • Environmentalism (1)
  • Fantasy Literature (1)
  • Film (2)
  • film studies (2)
  • Forensic Science (1)
  • front-end development (1)
  • Frontend Development (3)
  • Geology (1)
  • Governance (6)
  • Grammar (1)
  • graph theory (1)
  • Hardware (2)
  • Health (159)
    • Safety (127)
  • Health Science (1)
  • Human Resources (1)
  • Humanities (401)
    • Academia (168)
    • history (112)
    • Linguistics (16)
    • Literature (98)
  • information retrieval (2)
  • Information Science (3)
  • International Relations (1)
  • Internet of Things (1)
  • IT Operations (1)
  • Language Arts (1)
  • Law (302)
  • Law and Regulation (1)
  • Legal (1)
  • legal affairs (1)
  • Legal Compliance (3)
  • Legal Framework (1)
  • legal studies (1)
  • legal_affairs (1)
  • library science (1)
  • Life (1,508)
    • Cartoon (41)
    • D.I.Y (62)
    • Mindset (311)
    • Movies (57)
    • Philosophy (229)
    • Psychology (1,079)
      • Behavioral Science (299)
      • Cognitive Science (262)
    • Sci-Fi (65)
    • Tips and Tricks (32)
    • พุทธ (7)
  • logistics (1)
  • management (890)
    • knowledge management (295)
      • Documentation (98)
    • productivity (5)
    • Project Management (13)
    • strategy (3)
  • Marketing (1)
  • Markup Languages (1)
  • Mechanical Engineering (2)
  • Media (1)
  • media studies (3)
  • military history (1)
  • Military Technology (1)
  • Mystery (1)
  • Mythology (1)
  • Network (388)
    • IOT (24)
    • Nginx (26)
  • networking (46)
  • Neuroscience (1)
  • Object-Relational Mapping (1)
  • operating system (16)
  • Operating Systems (574)
    • Linux (207)
    • macOS (141)
      • Homebrew (25)
    • Shell Script (38)
      • Oh My ZSH (5)
    • Windows (99)
      • PowerShell (26)
  • Operations Management (1)
  • physics (1)
  • Pop Culture (1)
  • popular culture (1)
  • Process Management (1)
  • Process Modeling (1)
  • Programming (2,175)
    • .NET (116)
      • .NET Core EF (9)
      • C# (80)
    • API (477)
      • REST (8)
    • Database (699)
      • MariaDB (38)
      • MySql (69)
      • Oracle Database (24)
      • PostgreSQL (14)
      • RDBMS (55)
      • SQL Server (76)
        • T-SQL (26)
    • Programming Languages (368)
      • Java (95)
      • PHP (216)
      • Python (13)
      • Rust (31)
    • Software Architecture (7)
    • Software Engineering (65)
    • System Analyst (SA) (56)
    • Testing (124)
      • Automated Testing (110)
    • Web (1,438)
      • Apache HTTP Server (34)
      • Backend (1,146)
        • Laravel (54)
        • Spring Boot (15)
      • Frontend (309)
        • Angular (11)
        • CSS (67)
        • JavaScript (188)
        • jQuery (57)
        • Tabulator (24)
        • Tailwind CSS (4)
        • Vue.js (6)
      • WordPress (32)
  • Programming Language (5)
  • Property Law (2)
  • Property Management (3)
  • Public Policy (1)
  • Religion (1)
  • risk management (2)
  • Safety Engineering (3)
  • Science (1)
  • Science Fiction (9)
  • SecDevOps (792)
    • automation (255)
    • CI/CD (137)
    • Docker (89)
    • GIT (56)
    • SVN (6)
    • system (232)
      • System Administration (22)
  • Security (468)
    • Authentication (89)
    • Cryptography (42)
    • Cybersecurity (289)
  • Sensory Technology (1)
  • SEO (1)
  • Server Infrastructure (1)
  • Sociology (2)
  • Software Design (1)
  • Software Development (6)
  • software development lifecycle (1)
  • Software Development Practices (1)
  • Software Licensing (2)
  • Software Testing (1)
  • Space Exploration (1)
  • Spirituality (1)
  • sports (1)
  • SQL (1)
  • storage (1)
  • Storage Systems (1)
  • Storytelling (1)
  • structural engineering (1)
  • Supply Chain Management (1)
  • system architecture (1)
  • system design (4)
  • System Modeling (3)
  • Systems Modeling (1)
  • Systems Programming (2)
  • Technical Support (1)
  • technology (3)
  • Technology History (1)
  • transportation (1)
  • UI (1)
  • Uncategorized (665)
  • urban planning (7)
  • user experience (2)
  • User Experience Design (2)
  • User Interface Design (1)
  • UX Design (1)
  • Version Control (3)
  • visualization (1)
  • Web Design (2)
  • web development (54)
  • Web Standards (2)
  • web technology (2)
  • wellness (2)
  • กฎหมาย (3)
  • การขนส่ง (1)
  • การพัฒนาอสังหาริมทรัพย์ (1)
  • จราจร (1)
  • นวนิยายสืบสวน (1)
  • ผังเมือง (1)
  • วรรณกรรม (1)
  • สถาปัตยกรรม (1)
  • อสังหาริมทรัพย์ (2)
  • เรื่องเล่า (1)

Sirat WordPress Theme By VWThemes

Scroll Up
Go to mobile version