-1

I have one image and one video. I would like to add image as video just before actual video so i can stream video with intro frame for 5 seconds.

I found one command and full fill my requirement but in that command image added at the end of the video and i need beginning of the video. Let me share command below:

ffmpeg -i 1.mp4 -loop 1 -t 5 -i 2.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[0]split[base][full];[base]trim=0:5,drawbox=t=fill[base];[1][base]scale2ref=iw:ih:force_original_aspect_ratio=decrease:flags=spline[2nd][base];[base][2nd]overlay='(W-w)/2':'(H-h)/2'[padded];[full][0:a][padded][2:a]concat=n=2:v=1:a=1[v][a]" -c:v libx264 -c:a aac -strict -2 -map "[v]" -map "[a]" output.mp4

Image should be resize dynamically according to the video resolution. Best solution will be appreciate from bottom of heart.

Manoj Kag
  • 11
  • 2

1 Answers1

0

ffmpeg -i 1.mp4 -loop 1 -t 5 -i 2.jpg -f lavfi -t 5 -i anullsrc -filter_complex "[0:v]trim=0:5,drawbox=t=fill[base];[1][base]scale2ref=iw:ih:force_original_aspect_ratio=decrease:flags=spline[2nd][base2];[base2][2nd]overlay='(W-w)/2':'(H-h)/2'[padded];[padded][2:a][0:v][0:a]concat=n=2:v=1:a=1[v][a]" -c:v libx264 -c:a aac -map "[v]" -map "[a]" output.mp4

  • No need for the split filter.
  • Do not re-use labels. Each output label must be unique. For example, you used [base] several times. So I renamed the next one [base2].
  • Order of video is determined by the order given to the concat filter. I re-arranged it so [padded][2:a] plays before [0:v][0:a].
  • -strict -2 hasn't been needed since 2015 (it was for the AAC encoder). You don't need that unless your FFmpeg is very old.
llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thank you so much for your lovely help with great explanation. This command is working perfectly when i run in terminal and gives me output as per expectation but once i run it for iOS mobile app then i got one error that *****INFO: : Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 1800x1005 [SAR 216:216 DAR 120:67]***** Could you please help me out that why it is happened with iOS swift language and what should i do for fix it? – Manoj Kag Jun 10 '21 at 17:40
  • @ManojKag Show your ffmpeg command and the complete log. – llogan Jun 10 '21 at 18:05
  • yes you are right. It's working like charm. one last most important guidance needed from your end that video quality of the output is too poor so can we increase video quality in same command? – Manoj Kag Jun 10 '21 at 18:27
  • @ManojKag I need to see your command and the complete log to help you. – llogan Jun 10 '21 at 18:39
  • Thanks for wonderful helping. I will wait for your reply. I just update minor things in command that use h264_videotoolbox instead of libx264 for fix iOS app issue. I tried to set bit rate as per your one of the suggestion but i fail to generate out video. Let me share link [link](https://stackoverflow.com/questions/63460919/how-to-improve-the-output-video-quality-with-ffmpeg-and-h264-videotoolbox-flag) – Manoj Kag Jun 10 '21 at 18:50
  • @ManojKag I am unable to provide additional help without the information that I requested several times in previous comments. – llogan Jun 10 '21 at 19:25
  • Yes @llogan which information you need i will share with you. – Manoj Kag Jun 12 '21 at 13:02
  • @ManojKag The full ffmpeg command and the complete log. – llogan Jun 12 '21 at 20:49
  • I have created new post as comment section is not allowing to write more characters. Let me share full ffmpeg command and complete log [link](https://stackoverflow.com/questions/67955697/how-to-keep-video-quality-same-as-it-is-after-merge-intro-image-beggining-to-vid) – Manoj Kag Jun 13 '21 at 07:04