Y
Y
Yaroslav Ivanov2021-01-28 17:07:08
fmpeg
Yaroslav Ivanov, 2021-01-28 17:07:08

How to remove delay when transferring mp4 video?

When using mpegts, there is no delay, but this format is not played by the browser. When using mp4, everything is fine, but there is a delay of 6 seconds between sending data on the tcp socket.

How to remove the delay? or what to do to make mpegts play in the browser?

Settings:
mp4:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v h264 -movflags frag_keyframe+empty_moov -f mp4 tcp://127.0.0.1:4444


mpegts
ffmpeg -f gdigrab -framerate 30 -i desktop -c:v h264 -movflags frag_keyframe+empty_moov -f mpegts tcp://127.0.0.1:4444


Delay demo (file size):
mp4
oy-x7qmvvsr3annqyj9uunfiypy.gif

mpegts
2sthbggsiuitjooaseylbgc0rlo.gif

Code if you want to check for yourself
let net = require("net");
let fs = require("fs");
let file = fs.createWriteStream("tcp.mp4");
let server = net.createServer(socket => {
  socket.on("data", data => {
    file.write(data);
    //console.log(data)
    console.log(fs.statSync("tcp.mp4").size)
  })
})

server.listen(4444, "127.0.0.1");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Brendan Castaneda, 2021-02-10
@space2pacman

Try to do this ..
Next to app.js, put a bat file with this code and start it, it instantly takes off for me.
I changed the codec to mpeg4 this is the main one.

@echo off
color a
start node app.js
set c=ffmpeg
set f=-f gdigrab -framerate 30 -rtbufsize 999999k -thread_queue_size 9999999 -indexmem 9999999 -i desktop -c:v mpeg4 -qscale:v 3 -movflags frag_keyframe+empty_moov -f mp4 tcp://127.0.0.1:4444
%c% %f%
exit

-rtbufsize 1G Buffer size 1 gigabyte. By default, FFmpeg grabs frames from input and then does whatever you tell it to. For example, it recodes them and saves them to the output file. By default, if it receives a video frame "too early" (while the previous frame hasn't finished), it discards that frame so it can support real-time input. You can adjust this by setting the rtbufsize option, although note that if your encoding process doesn't keep up, you'll eventually start losing frames anyway (and using it at all may cause a slight delay). However, it may be useful to specify some buffer size, otherwise frames may be dropped unnecessarily.
-thread_queue_size - Sets the maximum number of packets to queue when reading from a file or device. Setting this value can force ffmpeg to use a separate input stream and read packets as soon as they arrive. Can be applied to each input listed after it.
-indexmem is the maximum memory used for the timestamp index (per thread).
Although it is a little old, it is fast enough -c:v mpeg4 -qscale:v 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question