2

I am trying to overlay a video on an image using the below command.

 -y -loop 1 -i snowflake.png
 -i crack.mp4
 -filter_complex "[0][1]scale2ref[i][m];[m][i]overlay[v]" -map [v] -map 0:a? -ac 2 output.mp4

The above command works but it overlay image on the video instead of video on the image.

I also try with the below command, but when I run that it removes the file path separator '\' from the path which results in the file not found error.

-loop 1 -i C:\Users\Desktop\SAM\Effects\snowflake.png
-vf "movie=C:\Users\Desktop\SAM\Effects\crack.mp4,scale=128:96[inner];[in][inner]overlay=70:70:shortest=1[out]" -y output.mp4

I saw a youtube video for the exact effect I want and copied the command from that but it still gives the same error no suitable output format. This is the command

-loop 1 -i C:\Users\Vivek\Desktop\SAM\Effects\A.jpg -i C:\Users\Vivek\Desktop\SAM\Effects\crack.mp4 -filter_complex "[1:v]colorkey=0x000000:0.5:0.5[ckout];[0:v][ckout]overlay[out]" -map "[out]" -c:a copy -c:v libx264 C:\Users\Vivek\Desktop\SAM\Effects\out.mp4

How to get this command working.

Below is the error screenshot. I can't post the logs here as the error is not appearing in logs.

Error

FYI: I am using ffmpeg in Unity using FFMPEG bind asset.

Vivek Mishra
  • 37
  • 1
  • 12
  • Your configuration shows `'\'` as the path separator, but you talk about `'/'`: which is it? Since you haven't shown the error message, I have to guess that `'\'` is being handled as an escape character, so you need either to double it or to use `'/'`, as your text says (the file system handles either separator - it is only the user interface that insists on `'\'`). – AFH Oct 06 '18 at 17:04
  • @AFH sorry about the wrong separator in the description. I am saying about the \ in the file path. – Vivek Mishra Oct 06 '18 at 17:07
  • Switch the inputs to the overlay and add shortest in the 1st cmd: `[i][m]overlay=shortest=1[v]` – Gyan Oct 06 '18 at 17:08
  • Then try my suggestions and add the error message to your question. – AFH Oct 06 '18 at 17:10
  • @Gyan I tried what you said but it gives error `no suitable output format found` – Vivek Mishra Oct 06 '18 at 17:15
  • @AFH I added \\ to the movie path but now it started giving No such file or directory error on the image path – Vivek Mishra Oct 06 '18 at 17:22
  • @AFH I have added the error screenshot – Vivek Mishra Oct 06 '18 at 17:55
  • 1
    It looks as though there is confusion between the different new-line formats for Linux/OSX/Windows. Have you been creating a script on a different OS from where you're running it? I don't know what native format Unity expects. – AFH Oct 06 '18 at 18:26
  • I am just writing the command in a notepad and pasting them back in unity on same system and that is Windows 10 – Vivek Mishra Oct 07 '18 at 04:35

1 Answers1

2

You are encountering invisible characters, zero width non-joiner (U+200C) and zero width space (U+200B), that are likely added by your text editor. You can see them if you paste into vim:

String[]sepCmd=new String[]{"-i",overlayUri,"-i",uri,"-filter_complex","[1:v][0<200c><200b>:v]scale2ref[ua][b<200c><200b>];<200c><200b>[ua]setsar=1,format=<200c><200b>yuva444p,colorchanne<200c><200b>lmixer=aa=0.5[u];[b]<200c><200b>[u]overlay"<200c><200b>,outputPa<200c><200b>th}

Associated errors that you may encounter with this infestation:

  • Invalid stream specifier:
  • No such filter: '‌​'
  • Error initializing filter
  • Unable to find a suitable output format

Remove these characters and use a better text editor: not Notepad or MS Word.

llogan
  • 57,139
  • 15
  • 118
  • 145
  • I now have so less reputation that I can't even upvote your answer. One last thing I want to ask, if I want the ouput as a gif file, will the same command work if I just change the ouput extension to .gif ? – Vivek Mishra Oct 10 '18 at 03:57
  • @VivekMishra Yes, but you should see [How do I convert a video to GIF using ffmpeg, with reasonable quality?](https://superuser.com/a/556031/110524) – llogan Oct 10 '18 at 17:56
  • Sorry to bother you again but I found one more issue. I created the desired video by using the given command and it works perfectly on laptop but when I run the same video in mobile devices, the overlay video is static and doesn't play at all while I can still here the sound of the video playing properly in devices. – Vivek Mishra Oct 11 '18 at 04:19
  • @VivekMishra I'll need to see the actual command and the log from ffmpeg. – llogan Oct 11 '18 at 16:54
  • Thanks for your reply but that issue seems resolved after I used gif instead of mp4 – Vivek Mishra Oct 11 '18 at 17:01
  • But I would like to ask is that how to switch the scaling parameter. Currently it scales image to fit the video width. While I want the video to stretch to the image width and height – Vivek Mishra Oct 11 '18 at 17:02
  • Sorry for all this but I am currently not able to understand how to write these filter commands – Vivek Mishra Oct 11 '18 at 17:03
  • @VivekMishra You should ask a new question regarding the scaling. Make sure to show the actual ffmpeg command and provide the log from ffmpeg. – llogan Oct 11 '18 at 17:08
  • I have posted the new question. This is the link https://superuser.com/questions/1365971/ffmpeg-scale-video-according-to-image-height-when-overlaying-video-on-image – Vivek Mishra Oct 11 '18 at 17:13