我注意到 FFMPEG 生成的视频的时长为 0安卓即使我尝试完全克隆也是如此。我尝试了以下命令,但唯一有效的命令是-movflags faststart
:
ffmpeg -i input.mp4 -c copy output.mp4
ffmpeg -i input.mp4 -c copy -movflags use_metadata_tags output.mp4
ffmpeg -i input.mp4 -c copy -movflags use_metadata_tags -map_metadata 0 output.mp4
ffmpeg -i input.mp4 -c copy -movflags faststart -brand mp42 -map_metadata 0 output.mp4
全部正常播放安卓,最后一个在图库中显示正确的时间。但问题是上传到抖音,因为尽管正在播放,但它认为时长为零,不允许上传。
输入数据(手机摄像头记录)
General
Complete name : G:\input.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (isom/mp42)
File size : 13.2 MiB
Duration : 7 s 647 ms
Overall bit rate : 14.4 Mb/s
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
com.android.version : 10
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference fra : 2 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 7 s 647 ms
Source duration : 7 s 579 ms
Bit rate : 14.1 Mb/s
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Rotation : 270°
Frame rate mode : Variable
Frame rate : 29.970 (29970/1000) FPS
Minimum frame rate : 14.940 FPS
Maximum frame rate : 10 000.000 FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.509
Stream size : 12.7 MiB (96%)
Source stream size : 12.7 MiB (96%)
Title : VideoHandle
Language : English
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
Color range : Limited
colour_range_Original : Full
Color primaries : BT.709
colour_primaries_Original : BT.601 PAL
Transfer characteristics : BT.709
transfer_characteristics_Origi : BT.601
Matrix coefficients : BT.709
matrix_coefficients_Original : BT.470 System B/G
mdhd_Duration : 7647
Codec configuration box : avcC
Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 7 s 595 ms
Bit rate mode : Constant
Bit rate : 96.0 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 89.0 KiB (1%)
Title : SoundHandle
Language : English
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
mdhd_Duration : 7595
ffprobe input.mp4
ffprobe version N-104856-g996b13fac4-20211212 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 11.2.0 (crosstool-NG 1.24.0.498_5075e1f)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20211212
libavutil 57. 11.100 / 57. 11.100
libavcodec 59. 14.100 / 59. 14.100
libavformat 59. 10.100 / 59. 10.100
libavdevice 59. 0.101 / 59. 0.101
libavfilter 8. 20.100 / 8. 20.100
libswscale 6. 1.101 / 6. 1.101
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000024a94212600] st: 0 edit list: 1 Missing key frame while searching for timestamp: 3037
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000024a94212600] st: 0 edit list 1 Cannot find an index entry before timestamp: 3037.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2022-04-17T11:43:02.000000Z
com.android.version: 10
Duration: 00:00:07.65, start: 0.000000, bitrate: 14438 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 1280x720, 14043 kb/s, SAR 1:1 DAR 16:9, 29.95 fps, 29.97 tbr, 90k tbn (default)
Metadata:
creation_time : 2022-04-17T11:43:02.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Side data:
displaymatrix: rotation of 90.00 degrees
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
Metadata:
creation_time : 2022-04-17T11:43:02.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
输出数据(-c copy -movflags faststart -brand mp42 -map_metadata 0
)
General
Complete name : G:\output.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (mp42/iso2/avc1/mp41)
File size : 12.8 MiB
Duration : 7 s 595 ms
Overall bit rate : 14.1 Mb/s
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
Writing application : Lavf59.10.100
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference fra : 2 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 7 s 580 ms
Bit rate : 14.0 Mb/s
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Rotation : 270°
Frame rate mode : Variable
Frame rate : 29.970 (29970/1000) FPS
Minimum frame rate : 14.940 FPS
Maximum frame rate : 10 000.000 FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.508
Stream size : 12.7 MiB (99%)
Title : VideoHandle
Language : English
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
Color range : Full
Color primaries : BT.601 PAL
Transfer characteristics : BT.601
Matrix coefficients : BT.470 System B/G
Codec configuration box : avcC
Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 7 s 595 ms
Bit rate mode : Constant
Bit rate : 96.0 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 89.0 KiB (1%)
Title : SoundHandle
Language : English
Default : Yes
Alternate group : 1
Encoded date : UTC 2022-04-17 11:43:02
Tagged date : UTC 2022-04-17 11:43:02
ffprobe output.mp4
ffprobe version N-104856-g996b13fac4-20211212 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 11.2.0 (crosstool-NG 1.24.0.498_5075e1f)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20211212
libavutil 57. 11.100 / 57. 11.100
libavcodec 59. 14.100 / 59. 14.100
libavformat 59. 10.100 / 59. 10.100
libavdevice 59. 0.101 / 59. 0.101
libavfilter 8. 20.100 / 8. 20.100
libswscale 6. 1.101 / 6. 1.101
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: mp42iso2avc1mp41
creation_time : 2022-04-17T11:43:02.000000Z
encoder : Lavf59.10.100
Duration: 00:00:07.60, start: 0.000000, bitrate: 14119 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/smpte170m, progressive), 1280x720, 14044 kb/s, SAR 1:1 DAR 16:9, 29.95 fps, 29.97 tbr, 90k tbn (default)
Metadata:
creation_time : 2022-04-17T11:43:02.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Side data:
displaymatrix: rotation of 90.00 degrees
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
Metadata:
creation_time : 2022-04-17T11:43:02.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
, progressive), 1280x720, 14044 kb/s, SAR 1:1 DAR 16:9, 29.95 fps, 29.97 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Side data:
displaymatrix: rotation of 90.00 degrees
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Metadata:
handler_name : SoundHandle
vendor_id : [0][0][0][0]
我认为问题在于缺少源持续时间视频元标签...
解决方案或技巧?