AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1456874
Accepted
spkane
spkane
Asked: 2019-07-07 12:05:44 +0800 CST2019-07-07 12:05:44 +0800 CST 2019-07-07 12:05:44 +0800 CST

在 VLC 播放列表中播放每个视频的最后 x 秒

  • 772

使用 VLC CLI,有没有办法播放播放列表中每个视频的最后 x 秒?

我知道:

--start-time=开始时间

The stream will start at this position (in seconds).

--stop-time=停止时间

 The stream will stop at this position (in seconds).

--run-time=运行时间

 The stream will run this duration (in seconds).

但是如果没有一些花哨的逻辑,这些都不是我想要的。

这是为了审查动作触发的视频,最后 15 秒通常是最有趣的,用于确定您是要观看还是保存整个视频。

vlc-media-player
  • 1 1 个回答
  • 133 Views

1 个回答

  • Voted
  1. Best Answer
    zx485
    2019-07-07T13:56:09+08:002019-07-07T13:56:09+08:00

    如果你也ffmpeg安装了,可以使用下面的脚本。它很简单,不会处理边界情况,例如短于 15 秒的视频或有缺陷的文件(您必须扩展它)。但除此之外,它使用 VLC 播放文件的最后 15 秒:

    #!/bin/bash
    secondsBeforeEnd=15
    length=`ffmpeg -i "$1" 2>&1 | grep "Duration" | cut -f4 -d' ' | cut -f1 -d','`
    secs=$(date "+%s" --date="$length")
    adjSecs=$(echo "$secs - $secondsBeforeEnd" | bc)
    adjTime=$(date +%T -d @$adjSecs)
    finalSecs=$(date +"%S" -d @$adjSecs)
    finalMins=$(date +"%M" -d @$adjSecs)
    finalHour=$(date +"%H" -d @$adjSecs)
    newStart=$(echo "$finalSecs + $finalMins*60 + $finalHour*3600" | bc)
    echo "=============================="
    echo "Original Length: $length"
    echo "Adjusted Length: $adjTime"
    echo "Starting time in seconds: $newStart"
    echo "=============================="
    vlc --start-time=$newStart "$1" "$2" "$3" "$4"
    

    当然,您可以将其放入for循环中。
    简单的 bash 脚本编写能力就足以做到这一点(您应该明白)。我还没有找到从 VLC 检索视频文件长度的方法,所以我不得不使用ffmpeg.


    第二种可能性是直接处理播放列表。为此,您需要一个 XSLT 处理器,例如xsltproc(Linux/Ubuntu) 或 Saxon-HE(Linux/Windows):

    例如,假设您有一个名为 的 VLC 播放列表play.xspf。
    然后将此 XSLT-1.0 样式表(名为playlist.xslt)应用到播放列表:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:l="http://xspf.org/ns/0/">
        <xsl:output method="text" indent="no" />
        <xsl:variable name="beforeEnd" select="15" />
    
        <xsl:template match="text()" />    
    
        <xsl:template match="/">
            <xsl:text>#!/bin/bash</xsl:text>
            <xsl:text>&#xd;&#xa;</xsl:text>
            <xsl:apply-templates select="l:playlist/l:trackList/l:track" />
        </xsl:template>
    
        <xsl:template match="l:track">
            <xsl:variable name="startTime" select="substring-before(l:duration div 1000,'.') - $beforeEnd" />
            <xsl:if test="$startTime > 0">
                <xsl:text>vlc --start-time=</xsl:text>
                <xsl:value-of select="$startTime" />
                <xsl:text> </xsl:text>
                <xsl:value-of select="l:location" />        
                <xsl:text>&#xd;&#xa;</xsl:text>
            </xsl:if>
        </xsl:template>
    
    </xsl:stylesheet>
    

    你可以这样做

    xsltproc playlist.xslt play.xspf
    

    或者

    java -jar saxon9he.jar -xsl:playlist.xslt play.xspf
    

    它的输出是一个bash脚本,该脚本将运行播放列表中每个文件的最后 15 秒,或者如果文件短于 15 秒则跳过该文件。

    如果您使用的是 Windows,只需删除该#!/bin/bash行(如有必要,将其余部分调整为批处理文件要求)。

    • 1

相关问题

  • 如何使年/日期标签在媒体播放器中完整显示?

  • VLC 可以播放未完成的 MP4 文件吗?

  • 将 RTSP 流保存到文件时出现错误的帧速率和元数据

  • VLC 音频到 Bluetooh,视频到 Chromecast?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve