2

I am cutting out silent parts of a 45 minute video (a lecture). To do this, I use a filter to select, say one hundred, non-silent parts (I already know their start and end times).

ffmpeg -i in.mp4
-vf "select='between(t,start_1,stop_1)+...+between(t,start_100,stop_100)', setpts=N/FRAME_RATE/TB"
-af "aselect='between(t,start_1,stop_1)+...+between(t,start_100,stop_100)', asetpts=N/SR/TB"
-c:a aac -c:v libx264 out.mp4

It works, but at the end of the video the images are delayed relative to the audio. After reading this answer I also added

-shortest -avoid_negative_ts make_zero -fflags +genpts

at the end of the command. It didn't help.

As audio and video are concatenated independently I'm not surprised that tiny time errors due to finite frame rate add up.

Is there a solution that doesn't involve saving every non-silent part as a file?

Louis
  • 21
  • 4
  • Use the concatdec method in the answer at https://superuser.com/a/1020455/ – Gyan Feb 05 '21 at 04:35
  • @Gyan As I understand this method is used for several input files. So I would have to decode the 45 minutes, split them, re-encode the useful segments, and let concatdec_select decode them once more to concat and re-encode them. Can this be done in one step? – Louis Feb 05 '21 at 10:38
  • You can list the same file multiple times with different inpoint/outpoints. – Gyan Feb 05 '21 at 10:39
  • @Gyan Thanks for the hint. I tried `ffmpeg -f concat -i filter.txt -vf 'select=concatdec_select,setpts=N/TB/FRAME_RATE' -af 'aselect=concatdec_select,asetpts=N/SR/TB' -c:v libx264 -c:a aac out.mp4`, `filter.txt` containing my file and inpoints/outpoints (I checked that they are correct). It didn't work, in `out.mp4` the cuts are so approximate that some parts are played twice. Actually the output is longer than the input X) – Louis Feb 05 '21 at 18:10
  • Were you then able to find a solution to this? – mcont Mar 18 '21 at 15:41
  • @mcont No I gave up. Maybe saving every non-silent part separately and then concatenating would work, it just probably takes longer. – Louis Mar 20 '21 at 11:50

0 Answers0