我刚刚发现了 FFmpeg,我需要它来将大量 MP4 文件剪辑到每个文件的最后 20 秒。每个 MP4 文件都有一个视频轨道和两个音轨。
我一直在使用这行代码:
for %F in (*.mp4) do ffmpeg -sseof -20 -i "%F" -map 0:v -map 0:a -c:v copy -c:a copy "%~nF_trimmed.mp4"
修剪很顺利,但音频有问题。在不取消修剪过程的情况下出现此错误:
[mp4 @ 0000025740443740] track 1: codec frame size is not set
[mp4 @ 0000025740443740] track 2: codec frame size is not set
请记住,我不熟悉编码,我只需要将其用于视频编辑目的。我一直在尝试寻找解决方法,但没有成功。有什么想法吗?
如果有用的话,这里是控制台完整流程:
D:\User Libraries\Desktop\Test>for %F in (*.mp4) do ffmpeg -sseof -20 -i "%F" -map 0:v -map 0:a -c:v copy -c:a copy "%~nF_trimmed.mp4"
D:\User Libraries\Desktop\Test>ffmpeg -sseof -20 -i "Test1.mp4" -map 0:v -map 0:a -c:v copy -c:a copy "Test1_trimmed.mp4"
ffmpeg version N-91024-g293a6e8332 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 18.100 / 56. 18.100
libavcodec 58. 19.101 / 58. 19.101
libavformat 58. 13.102 / 58. 13.102
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 21.100 / 7. 21.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Test1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2018-05-05T06:59:14.000000Z
date : 2018
Duration: 00:02:57.53, start: 0.000000, bitrate: 48706 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], 48332 kb/s, 59.83 fps, 59.94 tbr, 90k tbn, 120 tbc (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 171 kb/s (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 195 kb/s (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : SoundHandle
Output #0, mp4, to 'Test1_trimmed.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
date : 2018
encoder : Lavf58.13.102
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 48332 kb/s, 59.83 fps, 59.94 tbr, 90k tbn, 90k tbc (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 171 kb/s (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 195 kb/s (default)
Metadata:
creation_time : 2018-05-05T06:59:14.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame= 1211 fps=833 q=-1.0 Lsize= 124193kB time=00:00:19.98 bitrate=50911.9kbits/s speed=13.8x
video:123268kB audio:887kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.030864%
D:\User Libraries\Desktop\Test>ffmpeg -sseof -20 -i "Test2.mp4" -map 0:v -map 0:a -c:v copy -c:a copy "Test2_trimmed.mp4"
ffmpeg version N-91024-g293a6e8332 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 18.100 / 56. 18.100
libavcodec 58. 19.101 / 58. 19.101
libavformat 58. 13.102 / 58. 13.102
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 21.100 / 7. 21.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Test2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2018-05-05T07:02:30.000000Z
date : 2018
Duration: 00:02:36.73, start: 0.000000, bitrate: 49260 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], 48916 kb/s, 58.73 fps, 59.94 tbr, 90k tbn, 120 tbc (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 139 kb/s (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 195 kb/s (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : SoundHandle
[mp4 @ 000001cf28f53740] track 1: codec frame size is not set
[mp4 @ 000001cf28f53740] track 2: codec frame size is not set
Output #0, mp4, to 'Test2_trimmed.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
date : 2018
encoder : Lavf58.13.102
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 48916 kb/s, 58.73 fps, 59.94 tbr, 90k tbn, 90k tbc (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 139 kb/s (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 195 kb/s (default)
Metadata:
creation_time : 2018-05-05T07:02:30.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame= 1225 fps=834 q=-1.0 Lsize= 125448kB time=00:00:19.98 bitrate=51429.4kbits/s speed=13.6x
video:124591kB audio:815kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.034254%
答案1
此警告信息的来源表明来自以下帖子 ffmpeg MKV 转 MP4 错误轨道 1:未设置编解码器帧大小。
这 Gyan 的回答 说:
MP4 写入程序会尝试确定音轨是否为 VBR,以便写入一些其他元数据。它会检查编码的音频帧大小。MKV 写入程序不会执行此操作。
由于您正在重新混合,因此 Opus 无法使用这些数据,因此作者会抱怨。但该文件没有任何缺陷。
我将更改该消息的日志级别——一般用户其实不必担心这一点。
我的理解是,首先,此消息与要写入结果视频标题的元数据有关,对视频本身的正确性没有影响。这意味着可以忽略它(上面的答案说,对于最终用户来说,它确实应该被忽略)。
其次,这意味着由于视频和音频在任意点被切断,因此需要对视频和音频进行重新混合,即分离并重新编码(至少在切断点附近),这会导致音频编码器出现问题,同时没有可用的视频数据来补充其元数据。
无论如何,最终的视频文件应该是正确的,没有不利影响。您可以忽略此警告,