ffmpeg error reading header 问题解决

问题

在使用ffmpeg进行视频转码时,出现了如下错误:

1
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001b1af269840] error reading header F:/xxx.mp4: Operation not permitted    

解决

superuser 上看到了解决方案:

The sample MP4 is fragmented and so instead of having a global index for samples i.e. frames, the metadata is per fragment. Within each fragment’s metadata, there is a track run box trun which has data for all samples within the fragment. There was a change made in Oct 2017 (ffmpeg 4.0+) where ffmpeg would bail if the trun box indicated that 0 samples were stored within the fragment.

mp4box or older versions of ffmpeg do not fail, so you may use them to remux the file to regular MP4s.

1
ffmpeg-3.4 -i in.mp4 -c copy out.mp4

or

1
mp4box -add in.mp4 -new out.mp4

该 MP4 样本存在碎片化现象,因此不像通常那样为样本(即帧)设置全局索引,而是为每个片段设置元数据。在每个片段的元数据中,有一个 track run box(运行框),其中包含该片段内所有样本的数据。在 2017 年 10 月(ffmpeg 4.0 及以上版本)进行了一次更改,当时如果运行框显示片段内存储的样本数为 0,ffmpeg 将会终止运行。
mp4box 或者较旧版本的 ffmpeg 不会失败,所以您可以使用它们将文件重编码为常规的 MP4 格式。


ffmpeg error reading header 问题解决
https://taylorandtony.github.io/2025/05/06/ffmpeg-error-reading-header-问题解决/
作者
TaylorAndTony
发布于
2025年5月6日
许可协议