使用ffmpeg分割音频,重新组合视频,在开头插入黑帧


2

我正在使用ffmpeg从视频文件中分离出音频,将其转换为wav,然后将其与视频重新组合。当我这样做时,新视频一开始就有黑框。

以下是我正在运行的命令:

ffmpeg -i orig.mp4 orig-sound.wav 
ffmpeg -i orig.mp4 -i orig-sound.wav -map 0:0 -map 1:0 -vcodec copy new.mp4

我注意到,如果我在重新组合时添加-itsoffset -0.5,那么黑色帧不存在,但我不明白为什么这样做或为什么它是必要的。

ffmpeg -itsoffset -0.5 -i orig.mp4 -i orig-sound.wav -map 0:0 -map 1:0 -vcodec copy new.mp4

更多信息:这只适用于某些视频。

拆分命令输出

Running command: ffmpeg  -i shortvideo.mp4 -y /var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-13uwbwy.wav
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'shortvideo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:01:15.72, start: 0.072562, bitrate: 171 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 800x600, 40 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, wav, to '/var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-13uwbwy.wav':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    ISFT            : Lavf56.25.101
    Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, stereo, s16, 705 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc56.26.100 pcm_s16le
Stream mapping:
  Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size=    6524kB time=00:01:15.74 bitrate= 705.6kbits/s
video:0kB audio:6524kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.001168%

合并输出

Running command: ffmpeg  -i shortvideo.mp4 -i /var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-ou67bd.wav -map 0:0 -map 1:0 -vcodec copy -ab 127166 /var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-1lafn4z.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
Running command: ffmpeg  -i shortvideo.mp4 -y /var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-13uwbwy.wav
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'shortvideo.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:01:15.72, start: 0.072562, bitrate: 171 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 800x600, 40 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, wav, from '/var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-ou67bd.wav':
  Duration: 00:01:15.74, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, 2 channels, s16, 705 kb/s
Output #0, mp4, to '/var/folders/rr/x5blbrq14yj6zwlj5_y2y5gh0000gp/T/11555-44766-1lafn4z.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 800x600, q=2-31, 40 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 12288 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 22050 Hz, stereo, s16, 127 kb/s
    Metadata:
      encoder         : Lavc56.26.100 libvo_aacenc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (libvo_aacenc))
Press [q] to stop, [?] for help
[mp4 @ 0x7fbf0c826e00] Packet with invalid duration -2654 in stream 0164.3kbits/s
frame= 1807 fps=0.0 q=-1.0 Lsize=    1585kB time=00:01:15.76 bitrate= 171.4kbits/s
video:376kB audio:1177kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.046465%
1/1 videos completed...
Success: shortvideo.mp4
Processed 1623247 bytes in 3.064000129699707 seconds, at 0.5297803300547149 MB/sec

你能解释一下你想要完成的目标吗?...创建.wav输出有什么意义?....可能有更好的方法,了解更多信息可能有助于为您确定更好的解决方案。
occvtech 2015年

那么我将在这两个步骤之间插入另一个步骤 - 我将在音频中添加音频水印。但即使没有这一步,我也会得到黑框。为了添加水印,我必须首先使用wav格式的文件。
Keith Johnston

我对音频同步问题不是很了解......但有些事情你可以尝试,直到有更多知识渊博的人出现:在原始命令中,尝试用音频编码音频-c:a pcm_s16l3。如果这不起作用,您可以尝试在第二个命令中重置视频的PTS,但这需要使用视频过滤器(这反过来需要重新编码视频,并且不允许您进行流复制)。
occvtech 2015年

请包含每个命令的完整控制台输出。
llogan 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.