We want to encode large video files faster. To make encoding faster we are using multiple encoding servers. Below is our process of encoding flow

  1. First we split the video into small segments using below command

    ffmpeg -i F:\video_data_set\4k_compressed.mp4 -f segment -segment_time 5 -segment_start_number 1 -codec copy -copyts -avoid_negative_ts 1 F:\video_data_set\test\%d_4k_compressed.mp4

  2. Then we divide these segments among multiple encoding servers Each encoding server re-encode the segment using below command

    ffmpeg -hide_banner -i F:\video_data_set\test\1_4k_compressed.mp4 -c:a aac -ar 44100 -b:a 128k -c:v libx264 -x264opts nal-hrd=cbr:force-cfr=1 -pix_fmt yuv420p -profile:v baseline -level 3.0 -vf "scale=1280:-2,setdar=16:9" -b:v 3.9M -minrate 3.9M -maxrate 3.9M -bufsize 7.8M -preset ultrafast -crf 18 -r 30 -g 30 -threads 8 F:\video_data_set\test\1_4k_compressed_1.mp4

  3. When all segments have re-encoded then we join them to make single file using below command

    ffmpeg -hide_banner -f concat -safe 0 -i F:\video_data_set\test\files_2.txt -c copy -threads 8 F:\video_data_set\4k_compressed_1.mp4

All is performing well but the issue we are facing is that after each segment there is click sound in output audio.

For example I have encoded 5 segments having duration 6,6,3,6 and 6 seconds when I joined them using above mentioned command the output video has click sound at 6,12,15 and 21 seconds of video.

Can you please help me and let me know what is the cause of this click sound and how to fix and remove this click sound from output video.


This is a well-known effect: The -segment splits the video on a valid video entry point (i.e. an I-frame) but not always on a valid audio entry point.

The best way to work around this is to split the video and the audio in the first step:

ffmpeg -i F:\video_data_set\4k_compressed.mp4 -f segment -segment_time 5 -segment_start_number 1 -c:v copy -an -copyts -avoid_negative_ts 1 F:\video_data_set\test\%d_4k_compressed.mp4 -vn -c:a aac -ar 44100 -b:a 128k F:\video_data_set\test\audio.m4a

then proceed with the video segments as in your current workflow.

For the final step use

ffmpeg -hide_banner -f concat -safe 0 -i F:\video_data_set\test\files_2.txt -i F:\video_data_set\test\audio.m4a -map 0:v -map 1:a -c copy -threads 8 F:\video_data_set\4k_compressed_1.mp4

To re-add the audio.

  • Hello Eugen i have tested that solution but in this way audio out of sync i think some frames dropped in this way due to which audio is out of sync please help me to solve that problem – Faraz Ahmed Apr 13 '18 at 7:33
  • Have you tried the SETPTS and ASETPTS filters to nail the audio sync? – Eugen Rieck Apr 13 '18 at 7:35
  • No i have not tried these filters how i can use these filters – Faraz Ahmed Apr 13 '18 at 11:37
  • Read up in the documentation - the point ist to set the PTS for Video and Audio to the same value when splitting, as they might have an offset that doesn't show when interleaved. – Eugen Rieck Apr 13 '18 at 20:24
  • Hello Eugen can you please let me know to which splitting value we need to set audio and video pts i have read the documentation audio video pts have constant values – Faraz Ahmed Apr 17 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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