2

Can I use FFMPEG to insert an image every 20 frames in a video? I'm trying to create a subliminal message experiment and I thought it would be an easy way to make it but I can't find anything online.

I tried to make something myself and created a script that:
1.splits a file into audio and video files
2.splits the video into frames
3.overwrites every 20th image in the sequence with the message image
4.re-encoding the video
5.concatenating it with the original audio

this works but it's way more disk space consuming to be comfortable, is there a better way to do this?
any advice or thought would be happily welcome.

6

Make sure your message image is the same resolution as the video. Then run

ffmpeg -i video.mp4 -loop 1 -i msg.png
   -filter_complex "[0][1]overlay=enable='not(mod(n,20))':shortest=1[v]"
   -map "[v]" -map 0:a -c:a copy out.mp4

This will imprint the image on the very first frame as well. To avoid that,

ffmpeg -i video.mp4 -loop 1 -i msg.png
   -filter_complex "[0][1]overlay=enable='if(gt(n,0),not(mod(n,20)),0)':shortest=1[v]"
   -map "[v]" -map 0:a -c:a copy out.mp4
4
  • I get an error: "Invalid file index 1 in filtergraph description [0][1]overlay=enable='if(gt(n,0),not(mod(n,20)),0)':shortest=1[v]." for the second command, the first one isn't suitable because the imprint on the first frame is a problem. – Erez Hochman Mar 9 '17 at 12:17
  • Corrected typo. – Gyan Mar 9 '17 at 12:18
  • works like a charm! tell me something, if I insert a message with transparent background, is it possible to overlay it every X frames instead of overwriting the frame? – Erez Hochman Mar 9 '17 at 14:05
  • Yeah, if the FG has transparency, the BG will show through in those (transparent) areas. – Gyan Mar 9 '17 at 14:17

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.