3

As a follow-up to this question I'm now fighting with the synchronous editing of the video and audio.

I still try to cut the video by frames. While the resulting timestamps seem to be correct on the video, the audio is far from being in sync. It doesn't even help to add a constant time to asetpts. It seems to change with every different frame range I use.

Here's what I have (it's just relevant portions of a longer script):

SET SELECT=select='gte(n\,%4)*lte(n\,%5)'
SET ASELECT=aselect='gte(n\,%4)*lte(n\,%5)'
SET SETPTS=setpts='PTS-STARTPTS'
SET ASETPTS=asetpts='PTS-STARTPTS'
SET SCALE=scale='1280:-1'
SET CROP=%3
:
ffmpeg -y -i %1 -af %ASELECT%,%ASETPTS% -vf %SELECT%,%SETPTS%,%SCALE%,%CROP% ^
-ab 128k -crf 18 -pix_fmt yuv420p "%1 converted.mp4"

In short

  • it takes the crop-stuff and start/end frames as parameters
  • the source file starts with ~1 second of audio before the synchronised video starts
  • if I use no setpts/asetpts and no select/aselect, the resulting video starts with one second of a frozen frame with audio and then the video playing along with the audio synchronously
  • if I use no setpts/asetpts, the resulting video starts with a frozen frame, then the audio coming in and then starting with the passed start frame the video playing along with the audio synchronously
  • if I use no select/aselect, the resulting video has both video and audio start being off by that roughly one second
  • if I use all, the resulting video has both video and audio start with the start frame and the audio being off by that roughly one second

I guess the select/aselect is working fine, but the setpts/asetpts is causing the troubles. Working with only the video filters or audio filters makes it only worse.

Obviously I'm doing something wrong here. Therefore, can anyone please help me out here? Maybe one can even explain how the setpts and asetpts work together?

EDIT:
Other attempts:

ffmpeg -y -i %1 ^
-filter_complex %ASELECT%,%ASETPTS%;%SELECT%,%SETPTS%,%SCALE%,%CROP% ^
-ab 128k -crf 18 -pix_fmt yuv420p "%1 converted.mp4"

with two inputs (this is ultra slow):

ffmpeg -y -i %1 -i %1 ^
-filter_complex [1:1]%ASELECT%,%ASETPTS%[aud];[0:0]%SELECT%,%SETPTS%,%SCALE%,%CROP%[vid] ^
-map [vid] -map [aud] ^
-ab 128k -crf 18 -pix_fmt yuv420p "%1 converted.mp4"

1 Answer 1

2

To make it short, I failed.

What I'm doing now is converting the start and end frame number into a timestamp and use -ss and -t like everybody else in the world (*sigh*). I can do this since I know the FPS of the clip.

As far as the synchronisation is concerned I use the one-clip-in-two-input-files trick.

The final command now looks like:

ffmpeg -y -i %1 -itsoffset %audioDelay% -i %1 -vf %SCALE%,%CROP% ^
-ss %startTime% -t %duration% -r 25 ^
map=-map 0:0 -map 1:1 ^
-ab 128k -crf 18 -pix_fmt yuv420p "%~1 converted.mp4"

No more filters...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .