FFmpeg将M4S转换为MP4

7

我正在研究DASH技术,尝试优化终端用户的QoE体验。

我已经拥有了一个视频,并使用ffmpeg将其编码为不同的比特率,一切都很好,且该视频可通过dash播放。

我想要的是将用户接收到的片段合并成一个m4s文件并将该m4s文件转换为mp4格式。

我尝试了很多ffmpeg方法,但总是出现这个错误:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] could not find corresponding track id 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] could not find corresponding trex
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] error reading header
test2.m4s: Invalid data found when processing input

segment_1.m4s已经存在。

我该如何解决这个问题?


1
你在文件开头缺少初始化片段。 - szatmary
@szatmary 我自己编码了这些视频,只得到了38个片段。它们都合并到了那个m4s文件中,初始化片段应该放在哪里? - programming freak
3个回答

7

这是有效的

将m4s片段合并成一个文件,确保文件顺序正确。例如:

cat video-0.m4s >> all.m4s
cat video-1.m4s >> all.m4s
cat video-2.m4s >> all.m4s
cat video-3.m4s >> all.m4s
cat video-4.m4s >> all.m4s
cat video-5.m4s >> all.m4s
cat video-6.m4s >> all.m4s
cat video-7.m4s >> all.m4s
cat video-8.m4s >> all.m4s
cat video-9.m4s >> all.m4s
cat video-10.m4s >> all.m4s

然后一次性完成所有的转换。

ffmpeg -i all.m4s -c copy video.mp4

这不行

我尝试使用流式方法时遇到了同样的问题(无法找到相应的trex)。

我将我想要的所有文件放在一个名为all.txt的文件中,其中包含:

file 'video-0.m4s'
file 'video-1.m4s'
file 'video-2.m4s'
file 'video-3.m4s'
file 'video-4.m4s'
file 'video-5.m4s'
file 'video-6.m4s'
file 'video-7.m4s'
file 'video-8.m4s'
file 'video-9.m4s'
file 'video-10.m4s'

我尝试使用ffmpeg -f concat -safe 0 -i all.txt -c copy video.mp4,结果出现了同样的问题。

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] could not find corresponding track id 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] could not find corresponding trex
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] error reading header
[concat @ 0x55fde2cff900] Impossible to open 'rifle-1.m4s'
[concat @ 0x55fde2cff900] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, concat, from 'all.txt':
[... omitted ...]
all.txt: Input/output error

是的,相同的问题,所有文件都在同一个位置,但仍然出现错误。 - programming freak
1
初始化片段怎么样?初始化片段需要做什么? - Chandler
1
@user8783065,您需要在初始片段后连接m4s文件,可以使用如下命令:for x in *.dash *.m4s; do cat $x >> output.mp4; done,其中初始片段是一个.dash文件。 - Louis Maddox

3

我同意其他答案,但我发现一个略微不同的情况。将m4s文件连接起来后,我得到了相同的找不到相应的trex错误。

我得到了这个m3u8播放列表:

#EXTM3U
#EXT-X-VERSION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="/mypath/something.mp4"
#EXTINF:3.000,
something001.m4s
#EXTINF:3.000,
something002.m4s
#EXTINF:3.000,
something003.m4s
#EXTINF:3.000,
something004.m4s
#EXT-X-ENDLIST

我需要将所有文件与mp4文件连接起来。mp4文件只有1.1KB,没有视频,只有头文件。

连接文件后,有些软件可以播放,但兼容性不太好,所以你需要让FFmpeg来修复它。

以下方法适用于我:

ffmpeg -i allgluedtogetherinorder.mp4 -vcodec copy -strict -2 video_out.mp4

更新: 如果你的ffmpeg在编译时启用了m3u支持,那么你可以将播放列表转换为mp4格式,这样就可以解决所有问题并得到完美的视频。 你可能需要编辑m3u文件中文件路径,以便能够找到它们。 然后:

ffmpeg -i playlist.m3u -vcodec copy -strict -2 video_out.mp4

2

首先将初始化片段与其他片段文件拼接在一起。

Windows PowerShell:

对视频文件进行排序并列出列表。

 Get-ChildItem -name v1*.m4s| Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } > list.txt

音频文件

 Get-ChildItem -name a1*.m4s| Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } > list.txt

(参考:如何像Windows资源管理器一样按文件名排序?)

 type *init*.mp4 list.txt > Filename.mp4

Linux :

 ls -1v v1*.m4s > list.txt
 cat *init*.mp4 list.txt > Filename.mp4

1
请检查init.mp4中是否存在所有数据,如sps、pps等。 - mail2subhajit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接