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
  • แนวทางการบริหารจัดการสิทธิ์ (Privileged Access Management) สำหรับผู้ดูแลระบบคอนโดมิเนียมในภาวะวิกฤต
  • GNU General Public License v2 (GPL v2): ไลเซนส์ Copyleft คลาสสิก บังคับว่าถ้าใช้โค้ดนี้ โค้ดทั้งหมดต้องเป็น Open Source เช่นกัน
  • Tabulator 101: สร้าง Data Grid ประสิทธิภาพสูงจากข้อมูล JSON แบบง่ายด้วย JavaScript

Archives

Categories

  • .net core (36)
  • Action Genre (1)
  • Archaeology (1)
  • art (81)
  • Artificial Intelligence (1)
  • Astronomy (2)
  • Automotive History (1)
  • Bioengineering (1)
  • business (899)
    • Business Analysis (335)
    • Finance (32)
    • Real Estate (24)
  • cd (108)
  • chemistry (1)
  • ci (108)
  • Civil Engineering (1)
  • CMS (29)
  • collaboration (1)
  • Comics (1)
  • Command Line Interface (1)
  • Communication (140)
  • Community Governance (1)
  • Community Management (1)
  • compliance (1)
  • Computer Hardware (56)
  • computer science (1,905)
    • AI (390)
    • Biology (60)
      • Environment (34)
    • Cloud Computing (343)
    • Data Visualization (62)
    • Mathematics (44)
  • container (60)
  • Cosmology (2)
  • Culture (148)
  • data engineering (1)
  • data management (1)
  • Data Modeling (1)
  • Data Privacy (71)
  • Data Transformation (151)
  • Database Management (1)
  • Defense Technology (1)
  • 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,070)
    • architecture (957)
    • Building Engineering (76)
  • Entertainment (1)
  • Environmental Science (1)
  • Environmentalism (1)
  • Fantasy Literature (1)
  • Film (2)
  • film studies (2)
  • Forensic Science (1)
  • Frontend Development (2)
  • Geology (1)
  • Governance (1)
  • Grammar (1)
  • graph theory (1)
  • Hardware (2)
  • Health (159)
    • Safety (127)
  • Health Science (1)
  • Humanities (400)
    • Academia (166)
    • history (113)
    • Linguistics (16)
    • Literature (98)
  • information retrieval (1)
  • Information Science (3)
  • International Relations (1)
  • Internet of Things (1)
  • IT Operations (1)
  • Language Arts (1)
  • Law (302)
  • Legal Compliance (1)
  • Legal Framework (1)
  • library science (1)
  • Life (1,506)
    • Cartoon (41)
    • D.I.Y (61)
    • Mindset (311)
    • Movies (57)
    • Philosophy (229)
    • Psychology (1,076)
      • Behavioral Science (296)
      • Cognitive Science (261)
    • Sci-Fi (66)
    • 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)
  • Object-Relational Mapping (1)
  • operating system (15)
  • Operating Systems (574)
    • Linux (207)
    • macOS (141)
      • Homebrew (25)
    • Shell Script (38)
      • Oh My ZSH (5)
    • Windows (99)
      • PowerShell (26)
  • physics (1)
  • Pop Culture (1)
  • popular culture (1)
  • Process Management (1)
  • Process Modeling (1)
  • Programming (2,174)
    • .NET (116)
      • .NET Core EF (9)
      • C# (80)
    • API (475)
      • REST (8)
    • Database (690)
      • 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,436)
      • Apache HTTP Server (34)
      • Backend (1,143)
        • Laravel (54)
        • Spring Boot (15)
      • Frontend (309)
        • Angular (10)
        • CSS (65)
        • JavaScript (188)
        • jQuery (57)
        • Tabulator (24)
        • Tailwind CSS (4)
        • Vue.js (6)
      • WordPress (32)
  • Programming Language (4)
  • Property Law (1)
  • Property Management (1)
  • Religion (1)
  • risk management (1)
  • Safety Engineering (3)
  • Science (1)
  • Science Fiction (9)
  • SecDevOps (790)
    • automation (253)
    • CI/CD (137)
    • Docker (89)
    • GIT (56)
    • SVN (6)
    • system (232)
      • System Administration (22)
  • Security (464)
    • Authentication (89)
    • Cryptography (42)
    • Cybersecurity (281)
  • Sensory Technology (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 Systems (1)
  • Storytelling (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)
  • UI (1)
  • Uncategorized (664)
  • urban planning (1)
  • user experience (2)
  • User Experience Design (2)
  • User Interface Design (1)
  • UX Design (1)
  • Version Control (3)
  • visualization (1)
  • Web Design (2)
  • web development (45)
  • Web Standards (2)
  • web technology (2)
  • wellness (2)
  • กฎหมาย (1)
  • นวนิยายสืบสวน (1)
  • วรรณกรรม (1)
  • สถาปัตยกรรม (1)
  • อสังหาริมทรัพย์ (1)
  • เรื่องเล่า (1)

Sirat WordPress Theme By VWThemes

Scroll Up
Go to mobile version