FFmpeg messes up image overlay's width after adding it to a video












0















I'm using the following command to overlay a given image onto a video:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


The command works but it results in an overlay with a width different than the input overlay.png, it has the same height, though.



Here's overlay.png:



overlay.png preview



And here's how it appears in the video after FFmpeg overlaying:



video screenshot



overlay.png size is 274x79, but in the video it becomes about 324x79.



I've checked this question (ffmpeg overlay size) which suggest the use of scale, I changed the command to the following:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]scale=274:79
fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


But the results are still the same (bigger width), and I was able to confirm that scale does indeed work by editing it to scale=400:400 to check its effect.



What caused this and how can I keep the original size of overlay.png after overlaying it onto the video?





Edit:



ffmpeg -i Input.mp4 shows the following:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2018-12-30T12:38:54.000000Z
encoder : HandBrake 1.1.0 2018040700
Duration: 00:00:17.45, start: 0.000000, bitrate: 1179 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x480 [SAR 32:27 DAR 16:9], 1174 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2018-12-30T12:38:54.000000Z
handler_name : VideoHandler









share|improve this question

























  • Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

    – Gyan
    Jan 1 at 15:22











  • @Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

    – Eekan
    Jan 1 at 15:57
















0















I'm using the following command to overlay a given image onto a video:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


The command works but it results in an overlay with a width different than the input overlay.png, it has the same height, though.



Here's overlay.png:



overlay.png preview



And here's how it appears in the video after FFmpeg overlaying:



video screenshot



overlay.png size is 274x79, but in the video it becomes about 324x79.



I've checked this question (ffmpeg overlay size) which suggest the use of scale, I changed the command to the following:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]scale=274:79
fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


But the results are still the same (bigger width), and I was able to confirm that scale does indeed work by editing it to scale=400:400 to check its effect.



What caused this and how can I keep the original size of overlay.png after overlaying it onto the video?





Edit:



ffmpeg -i Input.mp4 shows the following:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2018-12-30T12:38:54.000000Z
encoder : HandBrake 1.1.0 2018040700
Duration: 00:00:17.45, start: 0.000000, bitrate: 1179 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x480 [SAR 32:27 DAR 16:9], 1174 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2018-12-30T12:38:54.000000Z
handler_name : VideoHandler









share|improve this question

























  • Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

    – Gyan
    Jan 1 at 15:22











  • @Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

    – Eekan
    Jan 1 at 15:57














0












0








0








I'm using the following command to overlay a given image onto a video:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


The command works but it results in an overlay with a width different than the input overlay.png, it has the same height, though.



Here's overlay.png:



overlay.png preview



And here's how it appears in the video after FFmpeg overlaying:



video screenshot



overlay.png size is 274x79, but in the video it becomes about 324x79.



I've checked this question (ffmpeg overlay size) which suggest the use of scale, I changed the command to the following:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]scale=274:79
fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


But the results are still the same (bigger width), and I was able to confirm that scale does indeed work by editing it to scale=400:400 to check its effect.



What caused this and how can I keep the original size of overlay.png after overlaying it onto the video?





Edit:



ffmpeg -i Input.mp4 shows the following:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2018-12-30T12:38:54.000000Z
encoder : HandBrake 1.1.0 2018040700
Duration: 00:00:17.45, start: 0.000000, bitrate: 1179 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x480 [SAR 32:27 DAR 16:9], 1174 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2018-12-30T12:38:54.000000Z
handler_name : VideoHandler









share|improve this question
















I'm using the following command to overlay a given image onto a video:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


The command works but it results in an overlay with a width different than the input overlay.png, it has the same height, though.



Here's overlay.png:



overlay.png preview



And here's how it appears in the video after FFmpeg overlaying:



video screenshot



overlay.png size is 274x79, but in the video it becomes about 324x79.



I've checked this question (ffmpeg overlay size) which suggest the use of scale, I changed the command to the following:



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[1:v]scale=274:79
fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1
[ovr1];
[0][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"


But the results are still the same (bigger width), and I was able to confirm that scale does indeed work by editing it to scale=400:400 to check its effect.



What caused this and how can I keep the original size of overlay.png after overlaying it onto the video?





Edit:



ffmpeg -i Input.mp4 shows the following:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2018-12-30T12:38:54.000000Z
encoder : HandBrake 1.1.0 2018040700
Duration: 00:00:17.45, start: 0.000000, bitrate: 1179 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x480 [SAR 32:27 DAR 16:9], 1174 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2018-12-30T12:38:54.000000Z
handler_name : VideoHandler






ffmpeg






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 15:56







Eekan

















asked Jan 1 at 14:30









EekanEekan

5119




5119













  • Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

    – Gyan
    Jan 1 at 15:22











  • @Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

    – Eekan
    Jan 1 at 15:57



















  • Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

    – Gyan
    Jan 1 at 15:22











  • @Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

    – Eekan
    Jan 1 at 15:57

















Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

– Gyan
Jan 1 at 15:22





Your video appears to be anamorphic What does ffmpeg -i input.mp4 say?

– Gyan
Jan 1 at 15:22













@Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

– Eekan
Jan 1 at 15:57





@Gyan I've edited my question to add ffmpeg -i Input.mp4 output.

– Eekan
Jan 1 at 15:57












1 Answer
1






active

oldest

votes


















1














Your video is 720x480 but with a 16:9 display ratio, basically a widescreen SD NTSC video.



You'll need to make it a square pixel video before overlaying the image, using the scale and setsar filter.



So,



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[0:v]scale=2*trunc(iw*sar/2):ih,setsar=1[0v];
[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1[ovr1];
[0v][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"





share|improve this answer


























  • Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

    – Eekan
    Jan 1 at 16:17











  • Corrected expr.

    – Gyan
    Jan 1 at 16:19











  • Unfortunately, I'm still getting the same error.

    – Eekan
    Jan 1 at 16:23











  • Needed to shift bracket

    – Gyan
    Jan 1 at 16:25











  • Thank you so much, this worked wonderfully! I've accepted the answer as well.

    – Eekan
    Jan 1 at 16:30











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996280%2fffmpeg-messes-up-image-overlays-width-after-adding-it-to-a-video%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Your video is 720x480 but with a 16:9 display ratio, basically a widescreen SD NTSC video.



You'll need to make it a square pixel video before overlaying the image, using the scale and setsar filter.



So,



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[0:v]scale=2*trunc(iw*sar/2):ih,setsar=1[0v];
[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1[ovr1];
[0v][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"





share|improve this answer


























  • Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

    – Eekan
    Jan 1 at 16:17











  • Corrected expr.

    – Gyan
    Jan 1 at 16:19











  • Unfortunately, I'm still getting the same error.

    – Eekan
    Jan 1 at 16:23











  • Needed to shift bracket

    – Gyan
    Jan 1 at 16:25











  • Thank you so much, this worked wonderfully! I've accepted the answer as well.

    – Eekan
    Jan 1 at 16:30
















1














Your video is 720x480 but with a 16:9 display ratio, basically a widescreen SD NTSC video.



You'll need to make it a square pixel video before overlaying the image, using the scale and setsar filter.



So,



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[0:v]scale=2*trunc(iw*sar/2):ih,setsar=1[0v];
[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1[ovr1];
[0v][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"





share|improve this answer


























  • Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

    – Eekan
    Jan 1 at 16:17











  • Corrected expr.

    – Gyan
    Jan 1 at 16:19











  • Unfortunately, I'm still getting the same error.

    – Eekan
    Jan 1 at 16:23











  • Needed to shift bracket

    – Gyan
    Jan 1 at 16:25











  • Thank you so much, this worked wonderfully! I've accepted the answer as well.

    – Eekan
    Jan 1 at 16:30














1












1








1







Your video is 720x480 but with a 16:9 display ratio, basically a widescreen SD NTSC video.



You'll need to make it a square pixel video before overlaying the image, using the scale and setsar filter.



So,



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[0:v]scale=2*trunc(iw*sar/2):ih,setsar=1[0v];
[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1[ovr1];
[0v][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"





share|improve this answer















Your video is 720x480 but with a 16:9 display ratio, basically a widescreen SD NTSC video.



You'll need to make it a square pixel video before overlaying the image, using the scale and setsar filter.



So,



ffmpeg -y 
-i "Input.mp4"
-loop 1 -t 17 -i "overlay.png"
-filter_complex
"[0:v]scale=2*trunc(iw*sar/2):ih,setsar=1[0v];
[1:v]fade=in:st=3:d=1:alpha=1,
fade=out:st=10:d=1:alpha=1[ovr1];
[0v][ovr1] overlay=(W-w)/2:H-h-10"
-codec:a copy
"Output.mp4"






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 16:25

























answered Jan 1 at 16:00









GyanGyan

33.1k22870




33.1k22870













  • Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

    – Eekan
    Jan 1 at 16:17











  • Corrected expr.

    – Gyan
    Jan 1 at 16:19











  • Unfortunately, I'm still getting the same error.

    – Eekan
    Jan 1 at 16:23











  • Needed to shift bracket

    – Gyan
    Jan 1 at 16:25











  • Thank you so much, this worked wonderfully! I've accepted the answer as well.

    – Eekan
    Jan 1 at 16:30



















  • Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

    – Eekan
    Jan 1 at 16:17











  • Corrected expr.

    – Gyan
    Jan 1 at 16:19











  • Unfortunately, I'm still getting the same error.

    – Eekan
    Jan 1 at 16:23











  • Needed to shift bracket

    – Gyan
    Jan 1 at 16:25











  • Thank you so much, this worked wonderfully! I've accepted the answer as well.

    – Eekan
    Jan 1 at 16:30

















Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

– Eekan
Jan 1 at 16:17





Thank you for your answer, but I'm getting the following error: [libx264 @ 0000000002fd0500] width not divisible by 2 (853x480).

– Eekan
Jan 1 at 16:17













Corrected expr.

– Gyan
Jan 1 at 16:19





Corrected expr.

– Gyan
Jan 1 at 16:19













Unfortunately, I'm still getting the same error.

– Eekan
Jan 1 at 16:23





Unfortunately, I'm still getting the same error.

– Eekan
Jan 1 at 16:23













Needed to shift bracket

– Gyan
Jan 1 at 16:25





Needed to shift bracket

– Gyan
Jan 1 at 16:25













Thank you so much, this worked wonderfully! I've accepted the answer as well.

– Eekan
Jan 1 at 16:30





Thank you so much, this worked wonderfully! I've accepted the answer as well.

– Eekan
Jan 1 at 16:30




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996280%2fffmpeg-messes-up-image-overlays-width-after-adding-it-to-a-video%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter