我有一个有趣的挑战,我认为可以用 ffmpeg 解决。我被发送了一个文件(mov/prores 或 h.264)的前几百 kb,以及来自同一文件的接近末尾的 1-2 兆块。我需要对较大的部分进行解复用,将音频提取为 wav 文件以供稍后处理。
我尝试将前几百 k 连接到后面的部分(bash shell 命令),然后对结果进行解复用。然而,这显然会导致重复的invalid frame header
错误(完整输出如下)。
因为我可以访问文件的开头,所以ffprobe -i
在该部分上运行正常。我曾希望在对后一部分进行解复用时使用此信息“强制”格式。但是我显然没有传递足够的参数来让 ffmpeg 对音频进行解复用:
$ ffmpeg -f mov -i prores_last_2_megs.mov output_audio.wav
ffmpeg version 2.8.6 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbb6c804200] moov atom not found
prores_last_2_megs.mov: Invalid data found when processing input
下面是一次解复用尝试的输出,使用了原始文件的前 150k 和该文件后面的 4 meg chuck:
ffmpeg -ss 00:00:00 -i prores_first_150k_and_last_4_megs.mov -to 00:00:02 -c copy -avoid_negative_ts 1 cut.mov
ffmpeg version 2.8.6 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[prores @ 0x7fee0880be00] invalid frame header
Last message repeated 20 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fee08808000] decoding for stream 0 failed
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fee08808000] Could not find codec parameters for stream 0 (Video: prores (apch / 0x68637061), none(bt709), 1920x1080, 124460 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'prores_first_150k_and_last_4_megs.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2015-11-03 10:23:58
timecode : 2332:32:21;21
Duration: 00:04:02.44, start: 0.000000, bitrate: 136 kb/s
Stream #0:0(eng): Video: prores (apch / 0x68637061), none(bt709), 1920x1080, 124460 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 2997 tbc (default)
Metadata:
creation_time : 2015-11-03 10:23:58
handler_name : Apple Alias Data Handler
encoder : Apple ProRes 422 (HQ)
Stream #0:1(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
creation_time : 2015-11-03 10:23:58
handler_name : Apple Alias Data Handler
Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
Metadata:
creation_time : 2015-11-03 10:23:58
handler_name : Apple Alias Data Handler
timecode : 2332:32:21;21
File 'cut.mov' already exists. Overwrite ? [y/N] y
[mov @ 0x7fee09800000] Codec for stream 0 does not use global headers but container format requires global headers
[mov @ 0x7fee09800000] Codec for stream 1 does not use global headers but container format requires global headers
Output #0, mov, to 'cut.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
timecode : 2332:32:21;21
encoder : Lavf56.40.101
Stream #0:0(eng): Video: prores (apch / 0x68637061), none, 1920x1080, q=2-31, 124460 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 2997 tbc (default)
Metadata:
creation_time : 2015-11-03 10:23:58
handler_name : Apple Alias Data Handler
encoder : Apple ProRes 422 (HQ)
Stream #0:1(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, stereo, 1536 kb/s (default)
Metadata:
creation_time : 2015-11-03 10:23:58
handler_name : Apple Alias Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 21 fps=0.0 q=-1.0 Lsize= 4011kB time=00:00:01.49 bitrate=21911.0kbits/s
video:3727kB audio:281kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.056156%
我可以更智能地切分标题(例如对于prores,从标题切到原子mdia
,然后在确定如何在适当的帧边界上切分它之后连接到后面的部分...
那么,如果你获得了视频文件中间的前几百 k 和随后的 2m 块,你会如何提取 wav 音频?谢谢!