2016-12-20 204 views
-1

我有一個很長的音頻部分 和一個短視頻部分,我想要複合器在一起。ffmpeg - 複合視頻和音頻和修剪音頻

我想下面的命令來MUX

  1. Video_0-0002.h264 - 整個文件(2秒長)
  2. Audio.wav - 從4至6秒
 
ffmpeg -y -i /Documents/viz-1/01/Video_0-0002.h264 -i /Documents/viz-1/01/Audio.wav -codec:v copy -f mp4 -af atrim=4:6 -strict experimental -movflags faststart /Documents/viz-1/01/Video_0-0001.mp4

但音頻混亂了...... 我該怎麼做才能正確?

也試過了,聽起來最後還是有沉默。

 
ffmpeg -y -i Video_0-0003.h264 -i Audio.wav -c:v copy -af atrim=6:8,asetpts=PTS-STARTPTS -strict experimental -movflags +faststart Video_0-0003.mp4 
 

    Input #0, h264, from 'Video_0-0003.h264': 
     Duration: N/A, bitrate: N/A 
     Stream #0:0: Video: h264 (Main), yuv420p(progressive), 388x388 [SAR 1:1 DAR 1:1], 30 fps, 30 tbr, 1200k tbn, 60 tbc 
    Guessed Channel Layout for Input Stream #1.0 : stereo 
    Input #1, wav, from 'Audio.wav': 
     Duration: 00:00:16.98, bitrate: 1411 kb/s 
     Stream #1:0: Audio: pcm_s16le ([1][0][0][0]/0x0001), 44100 Hz, stereo, s16, 1411 kb/s 
    Output #0, mp4, to 'Video_0-0003.mp4': 
     Metadata: 
     encoder   : Lavf57.56.100 
     Stream #0:0: Video: h264 (Main) ([33][0][0][0]/0x0021), yuv420p(progressive), 388x388 [SAR 1:1 DAR 1:1], q=2-31, 30 fps, 30 tbr, 1200k tbn, 1200k tbc 
     Stream #0:1: Audio: aac (LC) ([64][0][0][0]/0x0040), 44100 Hz, stereo, fltp, 128 kb/s 
     Metadata: 
      encoder   : Lavc57.64.101 aac 
    Stream mapping: 
     Stream #0:0 -> #0:0 (copy) 
     Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native)) 
    Press [q] to stop, [?] for help 
    [mp4 @ 0x7fca8f015000] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly 
    [mp4 @ 0x7fca8f015000] Starting second pass: moving the moov atom to the beginning of the file 
    frame= 60 fps=0.0 q=-1.0 Lsize=  242kB time=00:00:02.02 bitrate= 982.2kbits/s speed= 21x 
    video:207kB audio:32kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.382400% 
    [aac @ 0x7fca8f017400] Qavg: 1076.270 

+0

隔離的問題,是你的第一個步驟。你可以試試'-c:v copy -c:aac'和'-c copy'來檢查是否是音頻重新編碼問題?你的命令是否與其他文件一起工作?你嘗試過'-ss'和'-d'開關嗎?如果你分享你的努力,它會有幫助。 –

+0

我試過了-ss和-d,它在單個輸入上不起作用。 –

回答

0

嘗試

ffmpeg -y -i /Documents/viz-1/01/Video_0-0002.h264 -i /Documents/viz-1/01/Audio.wav -c:v copy -af atrim=4:6,asetpts=PTS-STARTPTS -strict experimental -movflags +faststart /Documents/viz-1/01/Video_0-0001.mp4 
+0

嗨我試過這個,但音頻仍然不同步。 –

+0

然後,您必須調整修剪值以匹配。 – Mulvya

+0

或者嘗試'-async 1'來防止音頻被拉伸。 – Xeoncross

0

你可以嘗試削減視頻定時音頻,然後瑪吉視頻和音頻軌道。 在單獨的ffmpeg進程中使用-vn和-an。

ffmpeg -i video.mp4 -c:v h264 -an -y video.h264 
ffmpeg -i video.mp4 -c:a aac -t 00:01:00 -vn -y audio.aac 

而對於瑪吉曲目:

ffmpeg -i auido.acc -i video.h264 -c:v copy -c:a copy -f mp4 -y out.mp4