About FFmpeg reporting Error when loading first segment and Invalid data found when processing input

About FFmpeg reporting Error when loading first segment and Invalid data found when processing input

The solution is written first

        If the ts file has been decrypted when downloading, FFmpeg should not bring #EXT-X-KEY when merging m3u8 files.

error screenshot

Error when loading first segment和Invalid data found when processing input
m3u8 file structure

train of thought

        At the beginning, I checked a lot of blogs about these two errors, as follows

  1. Use ffmpeg to convert m3u8 files to mp4
  2. M3u8 and TS file download and decryption: use FFmpeg to decrypt and merge ts files in m3u8 (2)
  3. ffmpeg merges m3u8 ts key files to solve Invalid data found when processing input error
  4. FFmpeg error Invalida data found when processing input

        I tried the methods of these blogs, and found that it didn't work. It was still the same Error when loading first segment and Invalid data found when processing input, and even more outrageous errors appeared according to some practices. So I reasoned a little bit about the process based on the output of FFmpeg.
        At first, I thought there was a problem with the ts file path, and the relative path caused FFmpeg to not read the correct file path, but after I made various attempts to modify the path, I found that the usage of the relative path is no problem.
        Then, through research, I found that all the ts lists were read, but according to the error message, it was a reading error when opening the first ts file, and this fragment could not be read.
        So, I thought about whether it is an encryption problem. The m3u8 I downloaded is encrypted. If the encryption is wrong, will it cause errors in reading the ts file, so I took a closer look at the m3u8 file. Both the ts file and the key file are downloaded locally, and the m3u8 file I used to merge is a regenerated m3u8 file that has converted the network path of ts and key into a local path.
        Then, I found the problem. When I downloaded the ts file, I had already decrypted the ts file. The ts file saved locally was already decrypted, and I wanted to decrypt these ts files again in FFmpeg. , which leads to a problem with the decrypted ts file data again. Naturally, it is impossible to use these problematic ts to splicing.
        Finally, I deleted the #EXT-X-KEY line in the m3u8 file, so the merge was successful.
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq1261275789/article/details/128535810