连接调整音量的视频时出现问题

连接调整音量的视频时出现问题

我拍摄了多个视频片段,并使用 ffmpeg 调整了它们的音量,然后尝试将它们连接起来(使用 ffmpeg),但是虽然我可以观看单独调整音量的片段文件并听到调整后的音量,但最终的连接版本包含视频但没有音频。

我用来调整音量的命令是:

> ffmpeg -y -i "E:/_Videos/Test/snippet.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts "E:/_Videos/Test/snippet.ts"


> ffmpeg -y -i "E:/_Videos/Test/snippet.ts" -vol 409 -vcodec copy  "E:/_Videos/Test/snippet_v1.6.ts"

我使用 concat 的命令是:

> ffmpeg -y -progress progressinfo.dat -f concat -safe 0 -i "E:/_Videos/Test/concat.txt" -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" "E:/_Videos/Test/_MERGED.mp4"

下面是其输出,但列出了多个与此类似的错误......

[aac @ 00000284490f6580] More than one AAC RDB per ADTS frame is not implemented. 
Update your FFmpeg version to the newest one from Git. If the problem still occurs, 
it means that your file has a feature which has not been implemented.

[aac @ 00000284490f6580] channel element 3.11 is not allocated
Error while decoding stream #0:1: Invalid data found when processing input

完整输出....

ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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-libx

ml2 --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 --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, concat, from 'E:/_Videos/Test/concat.txt':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1(und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 136 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 00000284495c5c40] using SAR=1/1
[libx264 @ 00000284495c5c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000284495c5c40] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 00000284495c5c40] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=9 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'E:/_Videos/Test/_MERGED.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.54.100 aac
[aac @ 00000284490f6580] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 00000284490f6580] channel element 3.11 is not allocated
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 00000284490f6580] channel element 3.11 is not allocated
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 00000284490f6580] channel element 3.11 is not allocated
.
.
.

我尝试了几种不同的方法来调整音量,并且尝试了 4.2.3 版和最新的 4.4.1 版,但都失败并出现相同的错误。(我在 Windows 10 上)

(无需调整音量即可连接原始 .ts 文件)。

我做错了什么(在将 mp4 与其他 mp4 连接之前,如何调整 mp4 的音量)?

答案1

因此解决方案(由 Rotem [非常感谢 Rotem] 在上面的评论中给出)似乎如 Rotem 所述,但稍微增加了使用“-async 1”来阻止声音与视频不同步。

我使用的完整命令如下:

// process the first clip (from a 640x480 30frames/s video)....

// Pull out a snippet from clip1.mp4 (39.51 seconds to 43.701 seconds...
ffmpeg -y -i "E:/_Videos/Test/clip1.mp4" -ss 39.51 -to 43.701 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" "E:/_Videos/Test/tmp/f1.mp4" 2>&1

// Create synthetic video with stereo audio...
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 10  "E:/_Videos/Test/tmp/f1.ts" 2>&1

// Execute conversion to TS
ffmpeg -y -i "E:/_Videos/Test/tmp/f1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts  "E:/_Videos/Test/tmp/f1.ts" 2>&1

// Set the volume...
ffmpeg -y -i "E:/_Videos/Test/tmp/f1.ts" -vol 25 -vcodec copy -acodec aac -async 1  "E:/_Videos/Test/tmp/f1_v0.1.ts" 2>&1

 
// now do the same for the next clip (with no volume adjust)...
// (a 1280x720 25frames/s video)...
ffmpeg -y -i "E:/_Videos/Test/clip2.mp4" -ss 0 -to 5.05 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" "E:/_Videos/Test/tmp/f2.mp4" 2>&1
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 10  "E:/_Videos/Test/tmp/f2.ts" 2>&1
ffmpeg -y -i "E:/_Videos/Test/tmp/f2.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts  "E:/_Videos/Test/tmp/f2.ts" 2>&1

 

// and the same for the next clip (with volume adjusted down)...
// (a 1280x720 25frames/s video)...
ffmpeg -y -i "E:/_Videos/Test/clip2.mp4" -ss 0 -to 5.05 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" "E:/_Videos/Test/tmp/f3.mp4" 2>&1
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 10  "E:/_Videos/Test/tmp/f3.ts" 2>&1
ffmpeg -y -i "E:/_Videos/Test/tmp/f3.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts  "E:/_Videos/Test/tmp/f3.ts" 2>&1
ffmpeg -y -i "E:/_Videos/Test/tmp/f3.ts" -vol 76 -vcodec copy -acodec aac -async 1  "E:/_Videos/Test/tmp/f3_v0.3.ts" 2>&1

 

// and the same for the next clip (with volume adjusted up)...
// (a 1280x720 25frames/s video)...
ffmpeg -y -i "E:/_Videos/Test/clip2.mp4" -ss 0 -to 5.05 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" "E:/_Videos/Test/tmp/f4.mp4" 2>&1
ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 10  "E:/_Videos/Test/tmp/f4.ts" 2>&1
ffmpeg -y -i "E:/_Videos/Test/tmp/f4.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts  "E:/_Videos/Test/tmp/f4.ts" 2>&1
ffmpeg -y -i "E:/_Videos/Test/tmp/f4.ts" -vol 409 -vcodec copy -acodec aac -async 1  "E:/_Videos/Test/tmp/f4_v1.6.ts" 2>&1


// then create a concat.txt file with the following contents
file 'f1_v0.1.ts'
file 'f2.ts'
file 'f3_v0.3.ts'
file 'f4_v1.6.ts'


// concatenate the listed files into the final _MERGED.mp4 file.
ffmpeg -y -progress progressinfo.dat -f concat -safe 0 -i "E:/_Videos/Test/tmp/concat.txt" -vf  "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black"  "E:/_Videos/Test/_MERGED.mp4" 2>&1

(我想现在没人知道如何在第一个和第二个剪辑之间进行淡入淡出吧?)

谢谢

相关内容