How can I get the length of a video in node.js - node.js

My backend needs to check to see if a video is under 60 seconds, or else it doesn't add the link to the database. Is there any easy solution if I have the file on disk? Something simple like videofile.getDuration()
I checked out FFMEG on npm but I'm not sure if that's what I need or if that's even up to date.

I use ffprobe for the task.
If you follow the README and you get to read the streams' info you will be able to get the duration by accessing the following tag on the video stream:
info.streams[0].tags.DURATION
There might be variants according to the kind of video file you are parsing, this example works with mkv.

Related

HTML5 Audio long buffering before playing

I'm currently making an electron app that needs to play some 40Mbyte audio file from the file system, maybe it's wrong to do this but I found that the only way to play from anywhere in the file system is to convert the file to a dataurl in the background script and then transfer it using icp, after that I simply do
this.sound = new Audio(dataurl);
this.sound.preload = "metadata"
this.sound.play()
(part of a VueJS component hence the this)
I did a profling inside electron and this is what came out:
Note that actually transferring the 40Mbytes audio file doesn't take that long (around 80ms) what is extremely annoying is the "Second Task" which is probably buffering (I have no idea) which last around 950ms, this is way too long and ideally would need it under <220ms
I've already tried changing the preload option to all available options and while I'm using the native html5 audio right now I've also tried howlerjs with similar results (seemed a bit faster tho).
I would guess that loading the file directly might be faster but even after disabling security measures put by electron to block the file:/// it isn't recognized as a valid URI by XHR
Is there a faster way to load the dataurl since all the data is there it just needs to be converted to a buffer or something like that ?
Note: I can not "pre-buffer" every file in advance since there is about 200 of them it just wouldn't make sense in my opinion.
Update:
I found this post Electron - throws Not allowed to load local resource when using showOpenDialog
don't know how I missed it, so I followed step 1 and I now can load files inside electron with the custom protocol, however, nor Audio nor howlerjs is faster, it's actually slower at around 6secs from click to first sound, is it that it needs to buffer the whole file before playing ?
Update 2:
It appears that the 6sec loading time is only effective on the first instance of audio that is created. I do not know why tho. After that the use of two instances (one playing and one pre-buffering) work just fine, however even loading a file that isn't loaded is instantaneous. Seems weird that it only is the firs one.

Metadata Extraction of mpegdash file

We use ffprobe, I want to know if mpegdash is supported by ffprobe. I wnt to extract technical metadata of the .mpd file for example bitrate. I do not want to stream or encode. I just want to read the data
When I run the command ffprobe -formats.I don't see .mpd extension being supported by ffprobe. Is there any library or extension that I need to add.
Or ffmpeg/ffprobe would not be enough to extract the data. Is thee any other tool or library available for this.
The mpd file is a simple text file that acts like an index and points to the different audio and video streams.
You can actually just read it directly if you are just looking for the bitrate - for example a mid with 5 different ABR bit rates versions of the vide stream will have the different 'representations' listed including their bitrates - e.g. it will include a line like:
<Representation id="2" width="1280" height="720" frameRate="30/1" bandwidth="2499968" codecs="avc1.4D4029">
Well as nobody has answered till now and I have found a solution. I will answer myself.
if we run the command :
ffmpeg -re -i <file_name.mpd> -f dash -
FFmpeg reads the XML file required to read. But it also reads the chunks and a lot of other information too. Which makes it difficult to extract technical metadata. The easiest option I concluded is to write the customised code to read the mpeg_dash.mpd file. as the XML file contains all the information.
To read more about the format of mpeg_dash file: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html
You can use existing MPD parser like https://github.com/carlanton/mpd-tools
https://javalibs.com/artifact/io.lindstrom/mpd-parser
I hope this helps.

Convert an RTSP/RTMP-Livestream with G.711 audio into RTMP/RTSP with aac-audio

im new at this forum and my english skills are not the best!
I have a website where i publish the videostreams of the cameras to show what happens inside during the nesting-time live! An guy with high IT-skills has build me a little Server for Restream it (Datarhei-Restreamer) But this guy has still no time and worse response-times...
To my Problem: The Restreamer dont support the "G.711" Audio-Codec from the cameras and the Livestream are still without audio at the website. So, i need to convert the Livestreams (RTSP and RTMP- in H.264) so that the audio changes to "aac" or something other supported. But i have no plan how to do this. I tried it with FFMPEG but i dont find the correct commands to get the my result. There is something with an Streaming-server to send the new created stream to - i dont get it into my head to do this (i need just a stream that are viewable with VLC player and then as input for my restreamer-server, jsut the same like ca
I want to change the source-stream into the correct codec (audio from G.711 to AAC, the rest like source) and then, put this "new" stream into my Restreamer-Server and it will work fine! (Tested with XSplitbroadcaster, but dont runs on Raspberry, only 1 instance runable but 2 livestreams needs to be encoded at same time) And this programm has annoying bugs (endless and not removeable error-messages, but running stream)
I have a new second raspberry that are planned as "live-encoder" for the restreamer-raspberry were the "new" streams are are going in (rtmp/rtsp-input on a graphical ui) I try it still with FFMPEG but still no result...
Sorry about this long text with all the language-issues but im really frustrated with it because i have purchased 2 new cameras with total 450 euros just to get the livestream with sound now :(
Finally, I found the best solution here and it works (https://github.com/datarhei/restreamer/issues/11). Inside the long discussion, use the solution written by svenerbeck on 4 Apr 2016. The essential part is written below.
Create a new live.json in /mnt/live.json with the upcoming modification:
"ffmpeg": {
"options": {
"native_h264": [
"-vcodec copy",
"-acodec aac",
"-f flv"
],
.....
Exec the container with
docker run ... -v /mnt/live.json:/restreamer/conf/live.json ....

Can you read the length of an mp3 file in python 3 on windows 10?

I am currently creating a music player in python 3.3 and I have a way of opening the mp3/wav files, namely through using through 'os.startfile()', but, this way of running the files means that if I run more than one, the second cancels the first, and the third cancels the second, and so on and so forth, so I only end up running the last file. So, basically, I would like a way of reading the mp3 file length so that I can use 'time.sleep(SongLength)' between the start of each file.
Thanks in advance.
EDIT:
I forgot to mention, but I would prefer to do this using only pre-installed libraries, as i am hoping to publish this online as a part of a (much) larger program
i've managed to do this Using an external module, as after ages of trying to do it without any, i gave up and used tinytag, as it is easy to install and use.
Nothing you can do without external libraries, as far as I know. Try using pymad.
Use it like this:
import mad
SongFile = mad.MadFile("something.mp3")
SongLength = SongFile.total_time()

Deal with ZIP-Buffer in node.js

I am building the server part of a webapp, using node.js. This involves getting data from thetvdb.com (API documentation of thetvdb).
The data comes as a zip file. HTTP download is no problem, however, parsing the file is. I actually never save the file, but just keep it in memory, as suggested in How to download and unzip a zip file in memory in NodeJs?
I have a buffer with valid data (same data as when I download the file with browser/curl...). However, adm-zip (I also tired other zip libraries, some suggest invalid zip length) can't open it. It does not show an error, but the zipEntries in the end have length of 0.
When I write out the buffer to the filesystem and open it with gui or cli tools it works.
I can't give a direkt link to the file, as it would involve my API key, however I re-uploaded it here.
I think I might have an answer for you:
Don't rely on npm install. I just ran the example that you linked to with the zip file you provided, and I get an output of "0".
I saw a comment on that other StackOverflow page, saying that the version of adm-zip on npm is not up to date. I grabbed a fresh copy of adm-zip from github, overwrote the one in my node_modules folder and reran the example code and now get the following:
...
<Actor>
<id>237811</id>
<Image>actors/237811.jpg</Image>
<Name>Peter Pratt</Name>
<Role>The Master</Role>
<SortOrder>3</SortOrder>
</Actor>
<Actor>
<id>23780s/237811.jpg</Image>
Give that a shot!

Resources