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

  • อธิบายการใช้ Range Types และ GiST Index ใน PostgreSQL เพื่อแก้ปัญหา Range Query สองคอลัมน์
  • เทียบ Database GUI (DBeaver, DBX, DataGrip, Navicat)
  • ทำความรู้จักกับ dbx (getdbx.com): Database Client ยุคใหม่ที่ออกแบบมาเพื่อ Developer
  • Vorsan: แอปสารพัดประโยชน์ที่คนใช้ Mac ควรมีติดเครื่อง
  • Apple แต่งตั้ง จอห์น เทอร์นัส (John Ternus) ขึ้นเป็น CEO โดยไม่ใช่ โจนี ไอฟ์ (Jony Ive)

Archives

Categories

  • .net core (47)
  • Accessibility (5)
  • Accounting (64)
  • Action Genre (2)
  • agriculture (3)
  • applied mathematics (65)
  • Archaeology (4)
  • art (97)
  • Artificial Intelligence (100)
  • Astronomy (4)
  • Automotive (9)
  • Automotive History (4)
  • Bioengineering (5)
  • Botany (1)
  • business (1,402)
    • Business Analysis (629)
    • Finance (42)
    • Real Estate (27)
  • cd (150)
  • chemistry (16)
  • ci (153)
  • Civil Engineering (29)
  • CMS (49)
  • collaboration (120)
  • Comics (1)
  • Command Line Interface (26)
  • Communication (157)
  • Communication Studies (1)
  • Community Governance (1)
  • Community Management (1)
  • compliance (1)
  • Computer Engineering (4)
  • Computer Hardware (63)
  • computer science (2,125)
    • AI (395)
    • Biology (132)
      • Environment (34)
    • Cloud Computing (482)
    • Data Visualization (65)
    • Mathematics (46)
  • construction (1)
  • Consumer Electronics (1)
  • container (63)
  • Content Creation (1)
  • Corporate Governance (3)
  • Corporate Law (1)
  • Cosmology (2)
  • Culture (151)
  • data engineering (5)
  • data management (5)
  • Data Modeling (1)
  • Data Privacy (80)
  • data science (7)
  • Data Transformation (171)
  • Database Management (6)
  • Database Systems (3)
  • Design (333)
    • UX/UI (45)
  • development (1)
  • devops (19)
  • DevOps Engineering (1)
  • Digital Electronics (1)
  • digital marketing (2)
  • digital technology (1)
  • disaster management (1)
  • e-learning (1)
  • Earth Science (1)
  • Ecology (1)
  • Education (4)
  • Electrical Engineering (4)
  • Electronics (4)
  • Electronics Engineering (3)
  • Embedded Systems (1)
  • engineering (1,157)
    • architecture (1,026)
    • Building Engineering (113)
  • Entertainment (1)
  • Entrepreneurship (1)
  • environmental (1)
  • Environmental Science (3)
  • Environmentalism (1)
  • Facility Management (1)
  • Fantasy Literature (1)
  • Film (2)
  • film studies (2)
  • Forensic Science (1)
  • front-end development (2)
  • Frontend Development (3)
  • Geographical Information System (1)
  • Geology (1)
  • Governance (6)
  • Grammar (1)
  • graph theory (1)
  • Hardware (5)
  • Health (159)
    • Safety (127)
  • health and safety (1)
  • health and wellness (1)
  • Health Science (2)
  • Home Appliances (1)
  • Human Resources (1)
  • Human-Computer Interaction (1)
  • Humanities (714)
    • Academia (499)
    • history (113)
    • Linguistics (16)
    • Literature (98)
  • Information Architecture (1)
  • Information Management (1)
  • information retrieval (2)
  • Information Science (14)
  • information security (1)
  • Information Technology (3)
  • Insurance (1)
  • International Relations (1)
  • Internet of Things (2)
  • IT Operations (1)
  • landscape architecture (1)
  • Language Arts (1)
  • Law (302)
  • Law and Regulation (1)
  • Legal (1)
  • Legal Advice (1)
  • legal affairs (1)
  • Legal Compliance (3)
  • Legal Framework (1)
  • legal studies (2)
  • legal_affairs (1)
  • library science (2)
  • Life (1,607)
    • Cartoon (41)
    • D.I.Y (62)
    • Mindset (311)
    • Movies (58)
    • Philosophy (229)
    • Psychology (1,236)
      • Behavioral Science (902)
      • Cognitive Science (501)
    • Sci-Fi (65)
    • Tips and Tricks (32)
    • พุทธ (7)
  • Lifestyle (1)
  • logic (1)
  • logistics (1)
  • Machine Learning (2)
  • management (890)
    • knowledge management (295)
      • Documentation (98)
    • productivity (5)
    • Project Management (16)
    • strategy (4)
  • manufacturing technology (1)
  • Marketing (1)
  • Markup Languages (1)
  • Mechanical Engineering (3)
  • Media (1)
  • media studies (3)
  • medicine (1)
  • military history (2)
  • Military Technology (1)
  • Mystery (1)
  • Mythology (1)
  • Network (388)
    • IOT (24)
    • Nginx (26)
  • network security (1)
  • networking (56)
  • Neuroscience (1)
  • Object-Relational Mapping (1)
  • operating system (18)
  • Operating Systems (583)
    • Linux (208)
    • macOS (143)
      • Homebrew (25)
    • Shell Script (44)
      • Oh My ZSH (5)
    • Windows (99)
      • PowerShell (26)
  • Operations Management (2)
  • physics (3)
  • Plumbing Systems (1)
  • Pop Culture (1)
  • popular culture (1)
  • Process Improvement (1)
  • Process Management (1)
  • Process Modeling (1)
  • Product Design (1)
  • Programming (2,249)
    • .NET (124)
      • .NET Core EF (9)
      • C# (82)
    • API (543)
      • REST (8)
    • Database (701)
      • MariaDB (38)
      • MySql (69)
      • Oracle Database (24)
      • PostgreSQL (16)
      • RDBMS (55)
      • SQL Server (76)
        • T-SQL (26)
    • Programming Languages (368)
      • Java (95)
      • PHP (216)
      • Python (13)
      • Rust (31)
    • Software Architecture (7)
    • Software Engineering (66)
    • System Analyst (SA) (56)
    • Testing (127)
      • Automated Testing (113)
    • Web (1,575)
      • Apache HTTP Server (39)
      • Backend (1,300)
        • Laravel (54)
        • Spring Boot (15)
      • Frontend (309)
        • Angular (11)
        • CSS (67)
        • JavaScript (188)
        • jQuery (57)
        • Tabulator (24)
        • Tailwind CSS (4)
        • Vue.js (6)
      • WordPress (35)
  • Programming Language (5)
  • Property Law (2)
  • Property Management (3)
  • Public Health (2)
  • Public Policy (1)
  • quality assurance (1)
  • Religion (4)
  • risk management (2)
  • Safety and Security (1)
  • Safety Engineering (3)
  • Science (1)
  • Science Fiction (9)
  • SecDevOps (847)
    • automation (320)
    • CI/CD (137)
    • Docker (89)
    • GIT (58)
    • SVN (6)
    • system (232)
      • System Administration (22)
  • Security (497)
    • Authentication (129)
    • Cryptography (43)
    • Cybersecurity (304)
  • Sensory Technology (1)
  • SEO (1)
  • Server Infrastructure (1)
  • social science (4)
  • Sociology (2)
  • Software Design (1)
  • Software Development (6)
  • software development lifecycle (1)
  • Software Development Practices (1)
  • Software Licensing (3)
  • Software Testing (2)
  • Space Exploration (1)
  • Spirituality (2)
  • sports (1)
  • SQL (1)
  • statistics (2)
  • storage (1)
  • Storage Systems (1)
  • Storytelling (1)
  • structural engineering (1)
  • supply chain (1)
  • Supply Chain Management (1)
  • system architecture (2)
  • system design (6)
  • System Modeling (3)
  • Systems Modeling (1)
  • Systems Programming (2)
  • Technical Support (1)
  • technology (5)
  • Technology History (1)
  • transportation (1)
  • UI (3)
  • Uncategorized (671)
  • urban planning (7)
  • user experience (5)
  • User Experience Design (3)
  • User Interface Design (1)
  • UX Design (3)
  • Version Control (3)
  • Virtualization (1)
  • visualization (1)
  • Web Design (2)
  • web development (67)
  • Web Standards (2)
  • web technology (2)
  • wellness (2)
  • กฎหมาย (3)
  • การขนส่ง (1)
  • การดูแลรถ (1)
  • การตลาด (61)
  • การบำรุงรักษา (1)
  • การพัฒนาอสังหาริมทรัพย์ (1)
  • การเงิน (61)
  • ความปลอดภัยทางไซเบอร์ (30)
  • จราจร (1)
  • ธุรกิจ (174)
  • นวนิยายสืบสวน (1)
  • ผังเมือง (1)
  • วรรณกรรม (1)
  • สถาปัตยกรรม (1)
  • อสังหาริมทรัพย์ (2)
  • เทคโนโลยี (14)
  • เรื่องเล่า (1)

Sirat WordPress Theme By VWThemes

Scroll Up