简体   繁体   English

从文件中提取M4V视频章节

[英]Extracting m4v video chapters from file

I'm creating an application built with the electron framework (to run html5 apps). 我正在创建一个使用电子框架构建的应用程序(以运行html5应用程序)。 I want to open m4v files from the webplayer, but i also need the video chapters. 我想从网络播放器中打开m4v文件,但我也需要视频章节。 Electron should have an API to open the video file like a simple text file, so how are those chapters formatted? Electron应该有一个API可以像简单的文本文件一样打开视频文件,那么这些章节的格式如何? Do anyone know a javascript method or library to extract those info? 有谁知道javascript方法或库来提取这些信息?

Also if anyone has a reference to a good documentation about this format, i would be happy to analyse it myself. 另外,如果有人参考了有关此格式的良好文档,我也很乐意自己分析。

Thank you very much in advance! 提前非常感谢您!

Found a way to do it myself, so I'll post it here to help future readers. 找到了自己完成此操作的方法,因此我将其发布在这里以帮助将来的读者。 This is not done using only javascript and rely on third part tools that you should find online. 这不是仅使用javascript而是依靠您应该在线上找到的第三方工具来完成的。 If someone has a better answer I'll be glad to read it! 如果有人有更好的答案,我将很高兴阅读它!

You should find a tool that is able to extract the chapters from videos that works as standalone from the console. 您应该找到一个工具,该工具能够从控制台中独立运行的视频中提取章节。 Then you can start the standalone as a child process and get the output. 然后,您可以启动独立的子进程并获取输出。 I used ffprobe in my test. 我在测试中使用了ffprobe。

Example code 范例程式码

const child_process = require("child_process");

var output = child_process.execSync("./tools/ffprobe -show_chapters path_to_video.mp4");
var string = Utf8ArrayToStr(output);

Here i downloaded a standalone of the ffprobe program and put it in the tools folder inside my project directory. 在这里,我下载了一个独立的ffprobe程序,并将其放在项目目录下的tools文件夹中。 Then i start that program as a child process and get the output. 然后,我将该程序作为子进程启动,并获得输出。 The output is in utf8 array, so i had to convert it. 输出是utf8数组,所以我不得不将其转换。 A function to translate utf8 array to string can be found in this stack overflow question . 此堆栈溢出问题中可以找到将utf8数组转换为字符串的函数。 After that, you should just parse the output as your program requires. 在那之后,您应该按照程序的要求解析输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM