How to eliminate freeze, buffer in mp4 file?

Questions involving a Windows version of FFmpeg.
Post Reply
Posts: 4
Joined: Tue Jan 09, 2018 10:50 am

How to eliminate freeze, buffer in mp4 file?

Post by joejim »

I am using Firefox addon Video Downloader Helper to capture HLS stream as mp4 file.
Sometimes HLS stream buffers, and during playback(mp4 file) in VLC, counter(time) just stop and video freezes. Then after few seconds or minute counter(time) skips and video file is playing again. I am sure this is due to original HLS stream buffering.

Is there anyway using ffmpeg command to eliminate these buffer spots and make a smooth playing mp4 file?
I don't mind skipped parts due to buffer. I just don't like whole mp4 video stopping till ready to play again. Sometimes few seconds skip but sometimes over minute or two before start playing again.

I am newbie. My only exposure to ffmpeg was few months ago converting .ts file to .mp4 file using ffmpeg command.
I used .\ffmpeg -i fox.ts -c copy FOX.mp4. It seem to skip thru buffers. So I tried the same command nor HLS stream. It didn't work.
Thanks in advance.

Posts: 30
Joined: Thu Nov 02, 2017 7:41 pm

Re: How to eliminate freeze, buffer in mp4 file?

Post by therube »

I am using Firefox addon Video Downloader Helper to capture HLS stream as mp4 file.
So you're actually capturing (all) the individual .ts segments?

What I have done is to capture the (single, what they call) "HLS streaming" stream.
That is actually a .m3u (.m3u8).

I then feed that (single) .m3u8 URL into ffmpeg which downloads the individual .ts segments (behind the scenes, if you will), output as you like - to a (single) .ts or .mp4.

So I use VDH to capture the .m3u (stream index/URL if you will).
Then use ffmpeg to capture the actual individual pieces (identified in the .m3u).

VDH (selecting the "HLS streaming" stream, aka m3u8) finds something like:

Code: Select all,s=,end=1515637765,limit=1/data=5637765/state=RfoO/reftag=109644/media=hlsA/23/17/1/55991.m3u8
I then send that to ffmpeg.

Code: Select all

ffmpeg  -i  ",s=,end=1515637765,limit=1/data=5637765/state=RfoO/reftag=109644/media=hlsA/23/17/1/55991.m3u8"  -c copy  out.mp4
out.mp4 should be the full stream.

I've never attempted to capture the individual .ts segments using VDH.
VDH (at least where I'm looking) calls those segments "MP2T", but they're actually ".ts" pieces, something like:

Code: Select all,s=,end=1515637765,limit=1/data=5637765/state=RfoO/reftag=109644/media=hlsA/23/17/9/79209.mp4/seg-86-v1-a1.ts
So this is the 86th piece of x-number of pieces.

VDH would need to capture all the individual .ts segments (assuming you're pulling down what they call MP2T's), without missing any, & it appears it doesn't "see" those pieces until the stream has come by (IOW the part of the video has played), so maybe if you jump around in the video, it sees pieces 1 2 3 4 5 ... 9 10 11 ... 36 37 38... & those parts that it doesn't see, it doesn't download & so end up as "holes" when you play it back, causing the pauses you're seeing.

If you started with the m3u (you would assume) that contains the complete index to all the pieces needed, so it is only a matter of getting them, concatenating them, & outputting them as you wish, which ffmpeg can do in one shot just by feeding it the .m3u file.

I'm not really familiar with VDH, but I'm not seeing where it can handle the .m3u directly, nor where it might know that it would have to capture all the .ts pieces & join them together? Maybe its there but I'm just missing it?

In any case, capture the .m3u (.m3u8) "URL" & feed that to ffmpeg & see if that gets your video in full, without "freezes".
(Some download managers may handle .m3u directly? Perhaps a different video capture program would handle it differently?

Grab Any Media, which I'm also not really familiar with, sees the .m3u & calls it "M3U8". It also sees the individual segments, calling them "TS". After that oh, not really sure what I'm doing. But in one manner, maybe I did a, oh I"m not sure, but one time I got a download that listing both the m3u & ALL the individual .ts pieces in a single file. Another time, I guess depending on how I went about things, I ended up with a file that contained the m3u & SOME of the .ts pieces [the 1 2 3 4 5 ... 9 10 11, kind of thing], & a batch file of the sort:

Code: Select all

ffmpeg  -safe "0"  -protocol_whitelist "file,http,https,tcp,tls,concat"  -f concat  -i "GrabAnyMediaToFFMPEG.txt"  -c copy "GrabAnyMediaToFFMPEG.mp4"
GrabAnyMediaToFFMPEG.txt, contained the m3u & (either some or all of the) .ts links (I guess depending on how I went about it).
GrabAnyMediaToFFMPEG.bat, the generated batch file is doing basically what I did manually above (though all I sent to ffmpeg was the .m3u itself).
And then it outputs to, what it calls GrabAnyMediaToFFMPEG.mp4 (where I just called it "out.mp4").

So with all that, I guess you eliminate the freeze by getting all the pieces, in full, & joining them together in the correct order.
Getting the URL to the .m3u & sending (only) that to ffmpeg seemed to do the trick for what I tried.

Post Reply