I have a few .ts files and the corresponding index.m3u8 file which looks something like this:
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:15
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:3.170,
seg-1-v1-a1.ts
#EXTINF:3.170,
seg-2-v1-a1.ts
#EXTINF:3.170,
seg-3-v1-a1.ts
#EXTINF:3.170,
seg-4-v1-a1.ts
#EXTINF:3.170,
seg-5-v1-a1.ts
#EXT-X-ENDLIST
So, to convert it into a single output.mp4 file, I ran the following command:
$ ffmpeg -i index.m3u8 -c copy output.mp4
...
[hls @ 0x55d78a3a6280] Opening 'seg-1-v1-a1.ts' for reading
...
[hls @ 0x55d78a3a6280] Opening 'seg-2-v1-a1.ts' for reading
[hls @ 0x55d78a3a6280] Opening 'seg-3-v1-a1.ts' for reading
[hls @ 0x55d78a3a6280] Opening 'seg-4-v1-a1.ts' for reading
[hls @ 0x55d78a3a6280] Opening 'seg-5-v1-a1.ts' for reading
...
Afterwards, I removed the .ts files and the index.m3u8 and just kept output.mp4. However, as it turns out, I did not have all the .ts files and the output was originally more like this:
$ rm seg-3-v1-a1.ts
$ ffmpeg -i index.m3u8 -c copy output.mp4
...
[hls @ 0x5555d0d86280] Opening 'seg-1-v1-a1.ts' for reading
...
[hls @ 0x5555d0d86280] Opening 'seg-2-v1-a1.ts' for reading
[hls @ 0x5555d0d86280] Opening 'seg-3-v1-a1.ts' for reading
[hls @ 0x5555d0d86280] Failed to open segment 3 of playlist 0
[hls @ 0x5555d0d86280] Opening 'seg-4-v1-a1.ts' for reading
[hls @ 0x5555d0d86280] Opening 'seg-5-v1-a1.ts' for reading
...
When watching the video, at the position of the missing segment, the picture freezes for a few seconds, then the video continues. I have a few .mp4 files and I want to find out which of them are affected by this issue. Without having the original log, how can I find out if there were any segments missing when I ran the ffmpeg -i index.m3u8 -c copy output.mp4 command?
I found one command at https://superuser.com/questions/100288/how-can-i-check-the-integrity-of-a-video-file-avi-mpeg-mp4 which unfortunately doesn't find any issues:
$ ffmpeg -v error -i output.mp4 -f null -
$ echo $?
0
You can check if r_frame_rate and avg_frame_rate are equal.
The command below:
will output (for correct file) something like this:
and (for corrupted file) something like this:
This method is not perfect, but in many cases should be totally fine.
Second method, intuitive and in my honest opinion working only in specific conditions, is looking for freezes. For example:
It can work, but only if stream is really specific.
Another method, similar to the first one, is looking for VFR.
The command:
will output:
for corrupted file. For correct it will be:
This is similar to the first method, but contrary to appearances – different!
As far as I know, it is possible to have equal
r_frame_rateandavg_frame_rate, while VFR is not zero!In my honest opinion checking VFR is the best option and may work. That's bad you didn't provide any example file. I assume that your stream should've VFR:0.000000, but that's reading tea leaves.
As far as I know, there is no universal method to do what you need. I hope any of my examples will fit, but it really depends and need to be tested in practice, on the right files. Exactly these, which you want to check.
According to your reply below my answer, I have implemented simple script that's:
For me it's working fine.