0

using ffmpeg, using ffmpeg, how to concetrate multiple videos into one, but audio will be sync per video in linux?

I have tried async, vsync, atempo but i dont know how make ffmpeg to autosync audio for each video.

In other words, how to match audio with video frame rate in each video independently when framerate is different in each video, otherwise freeze frames are produced. If -an parameter is specified no freeze frames exists in video output.

I found that tuning atempo can match video duration. How i can making work automatically in each video?

ffmpeg -f concat -safe 0 -i "./vids.txt" -c:v libx265 -video_track_timescale 90000 -x265-params crf=18 -pix_fmt yuvj420p -af atempo=1.1 vid_outatempo1_1.mkv

video 1

General
Complete name :
/mnt/temp_dir/v1_tyes.mp4
Format :
MPEG-4
Format profile :
Base Media
Codec ID :
isom (isom/iso2/mp41)
File size :
94.3 MiB
Duration :
49 s 174 ms
Overall bit rate :
16.1 Mb/s
Frame rate :
29.480 FPS
Writing application :
Lavf59.27.100
Video
ID :
1
Format :
HEVC
Format/Info :
High Efficiency Video Coding
Format profile :
Main@L4@Main
Codec ID :
hev1
Codec ID/Info :
High Efficiency Video Coding
Duration :
49 s 153 ms
Bit rate :
16.0 Mb/s
Width :
1 920 pixels
Height :
1 080 pixels
Display aspect ratio :
16:9
Frame rate mode :
Variable
Frame rate :
29.480 FPS
Minimum frame rate :
14.750 FPS
Maximum frame rate :
29.500 FPS
Original frame rate :
29.500 FPS
Color space :
YUV
Chroma subsampling :
4:2:0 (Type 0)
Bit depth :
8 bits
Scan type :
Progressive
Bits/(Pixel*Frame) :
0.262
Stream size :
93.8 MiB (100%)
Title :
VideoHandle
Writing library :
x265 3.5+1-f0c1022b6:[Linux][GCC 12.2.0][64 bit] 8bit+10bit+12bit
Encoding settings :
cpuid=1111039 / frame-threads=4 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=1920x1080 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=3 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-hrd / info / hash=0 / no-temporal-layers / open-gop / min-keyint=25 / keyint=250 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=6 / scenecut=40 / hist-scenecut=0 / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=3 / limit-refs=1 / no-limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=3 / selective-sao=4 / early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=0.00 / no-rd-refine / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=18.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=2 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=1 / overscan=0 / videoformat=5 / range=1 / colorprim=5 / transfer=2 / colormatrix=2 / chromaloc=1 / chromaloc-top=0 / chromaloc-bottom=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=255 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / hist-threshold=0.03 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / scenecut-aware-qp=0conformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass
Language :
English
Color range :
Full
Color primaries :
BT.601 PAL
Codec configuration box :
hvcC
Audio
ID :
2
Format :
AAC LC
Format/Info :
Advanced Audio Codec Low Complexity
Codec ID :
mp4a-40-2
Duration :
49 s 174 ms
Source duration :
49 s 195 ms
Bit rate mode :
Constant
Bit rate :
69.5 kb/s
Channel(s) :
1 channel
Channel layout :
M
Sampling rate :
48.0 kHz
Frame rate :
46.875 FPS (1024 SPF)
Compression mode :
Lossy
Stream size :
417 KiB (0%)
Source stream size :
417 KiB (0%)
Title :
SoundHandle
Language :
English
Default :
Yes
Alternate group :
1

video 2

General
Complete name :
/mnt/temp_dir/v2_h265.mp4
Format :
MPEG-4
Format profile :
Base Media
Codec ID :
isom (isom/iso2/mp41)
File size :
36.3 MiB
Duration :
54 s 763 ms
Overall bit rate :
5 554 kb/s
Frame rate :
29.529 FPS
Writing application :
Lavf59.27.100
Video
ID :
1
Format :
HEVC
Format/Info :
High Efficiency Video Coding
Format profile :
Main@L4@Main
Codec ID :
hev1
Codec ID/Info :
High Efficiency Video Coding
Duration :
54 s 727 ms
Bit rate :
5 478 kb/s
Width :
1 920 pixels
Height :
1 080 pixels
Display aspect ratio :
16:9
Frame rate mode :
Variable
Frame rate :
29.529 FPS
Minimum frame rate :
9.861 FPS
Maximum frame rate :
29.583 FPS
Original frame rate :
29.583 FPS
Color space :
YUV
Chroma subsampling :
4:2:0 (Type 0)
Bit depth :
8 bits
Scan type :
Progressive
Bits/(Pixel*Frame) :
0.089
Stream size :
35.7 MiB (99%)
Title :
VideoHandle
Writing library :
x265 3.5+1-f0c1022b6:[Linux][GCC 12.2.0][64 bit] 8bit+10bit+12bit
Encoding settings :
cpuid=1111039 / frame-threads=4 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=1920x1080 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=3 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-hrd / info / hash=0 / no-temporal-layers / open-gop / min-keyint=25 / keyint=250 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=6 / scenecut=40 / hist-scenecut=0 / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=3 / limit-refs=1 / no-limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=3 / selective-sao=4 / early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=0.00 / no-rd-refine / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=18.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=2 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=1 / overscan=0 / videoformat=5 / range=1 / colorprim=5 / transfer=2 / colormatrix=2 / chromaloc=1 / chromaloc-top=0 / chromaloc-bottom=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=255 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / hist-threshold=0.03 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / scenecut-aware-qp=0conformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass
Language :
English
Color range :
Full
Color primaries :
BT.601 PAL
Codec configuration box :
hvcC
Audio
ID :
2
Format :
AAC LC
Format/Info :
Advanced Audio Codec Low Complexity
Codec ID :
mp4a-40-2
Duration :
54 s 763 ms
Source duration :
54 s 784 ms
Bit rate mode :
Constant
Bit rate :
70.0 kb/s
Channel(s) :
1 channel
Channel layout :
M
Sampling rate :
48.0 kHz
Frame rate :
46.875 FPS (1024 SPF)
Compression mode :
Lossy
Stream size :
468 KiB (1%)
Source stream size :
468 KiB (1%)
Title :
SoundHandle
Language :
English
Default :
Yes
Alternate group :
1

My tries failed - either 2nd video audio is truncuated, or video is truncuated or produce freezed frames.

1 Answer 1

0

UPDATE: Finally, fixing frame rates to 30 for each video, as well fixing audio encoder, ffmpeg -i v1.mp4 -strict -2 -c:v libx265 -video_track_timescale 90000 -vf fps=30 -x265-params crf=18 -pix_fmt yuvj420p -c:a flac -ar 48000 -b:a 64k v2_same.mp4

then concetrated them without rencoding them, solved my problem

ffmpeg -f concat -safe 0 -i './vids.txt' -strict -2 -c copy -fflags +genpts output.mp4

However, I feel that ffmpeg must provide an option to "fix frame rate to audio sync" without needing to run a second ffmpeg to concentrate them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.