如何使用與某些檔案相同的編解碼器和參數進行 ffmpeg 編碼?

如何使用與某些檔案相同的編解碼器和參數進行 ffmpeg 編碼?

我需要合併兩個不同的視訊文件,我正在使用無損剪切為了任務。但它表示檔案需要具有相同的編解碼器、尺寸、幀速率。

源是帶有 Vorbis 的 mkv V_MPEG4/ISO/AVC,目標是帶有 ac3 的 avi xvid。

  • 使用 ffmpeg 編碼的兩個檔案的完整參數
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 6.20 MiB
Duration                                 : 46 s 280 ms
Overall bit rate                         : 1 124 kb/s
Writing application                      : Lavf58.45.100

Video
ID                                       : 0
Format                                   : MPEG-4 Visual
Format profile                           : Advanced Simple@L5
Format settings                          : BVOP2
Format settings, BVOP                    : 2
Format settings, QPel                    : No
Format settings, GMC                     : No warppoints
Format settings, Matrix                  : Default (MPEG)
Muxing mode                              : Packed bitstream
Codec ID                                 : XVID
Codec ID/Hint                            : XviD
Duration                                 : 46 s 280 ms
Bit rate                                 : 921 kb/s
Width                                    : 576 pixels
Height                                   : 432 pixels
Display aspect ratio                     : 3:2
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.148
Stream size                              : 5.08 MiB (82%)
Writing library                          : XviD 64

Audio
ID                                       : 1
Format                                   : AC-3
Format/Info                              : Audio Coding 3
Commercial name                          : Dolby Digital
Codec ID                                 : 2000
Duration                                 : 46 s 254 ms
Bit rate mode                            : Constant
Bit rate                                 : 192 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 44.1 kHz
Frame rate                               : 28.711 FPS (1536 SPF)
Bit depth                                : 16 bits
Compression mode                         : Lossy
Stream size                              : 1.06 MiB (17%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 35  ms (0.87 video frame)
Interleave, preload duration             : 347  ms
Service kind                             : Complete Main
  • 我想要重新編碼/編碼的文件的參數(以便具有上面顯示的參數):
Format                                   : Matroska
Format version                           : Version 4
File size                                : 2.36 MiB
Duration                                 : 27 s 999 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 706 kb/s
Writing application                      : Lavf58.45.100
Writing library                          : Lavf58.45.100
ErrorDetectionType                       : Per level 1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 27 s 933 ms
Bit rate                                 : 564 kb/s
Width                                    : 854 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.303 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.045
Stream size                              : 1.88 MiB (80%)
Default                                  : Yes
Forced                                   : No
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio
ID                                       : 2
Format                                   : Vorbis
Format settings, Floor                   : 1
Codec ID                                 : A_VORBIS
Duration                                 : 27 s 837 ms
Bit rate mode                            : Variable
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -52 ms
Stream size                              : 435 KiB (18%)
Writing application                      : Lavc58.91.100
Writing library                          : libVorbis (Reducing Environment) (20200704 (Reducing Environment))
Default                                  : Yes
Forced                                   : No

如何從目標檔案中提取所有資料並將其作為參數輸入到 FFmpeg 來源檔案編碼命令?我正在查找是否有此腳本,但找不到。

答案1

你必須手動完成。

ffmpeg -i input.mkv -c:v libxvid -vf scale=-2:432 -r 25 -profile:v 0 -level 5 -vtag XVID -mpeg_quant 1 -b:v 921k -bf 2 -c:a ac3 -ac 2 -ar 44100 output.avi

答案2

我還沒有找到任何好的解決方案,但是有一個 Linux bash 腳本嘗試自動執行尋找要合併的影片片段中的差異的任務,並建議命令來修復差異。

答案3

這很接近:“在不預先定義尺寸的情況下縮放一個視頻以匹配另一個視頻”,將兩個視頻並排放置,並使第二個視頻比例與第一個視頻匹配:

ffmpeg -i vid1.mp4 -i vid2.mp4 -filter_complex "[1:v][0:v]scale2ref=oh*mdar:h=in_h:[v1][v0];[v0][v1]hstack[vo]" -map "[vo]" ./output-video.mp4

來源

相關內容