FFMPEG Merge mp4 to mp4 batch












1















Hi sorry if this has already been asked but ive got intro.mp4 and over 1000 mp4 in another folder what i need is intro.mp4 to be added to every mp4 in folder im using ubuntu whats the best way to do this.



all the mp4 have the same encoding



ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy output.mp4


this command words for one at a time
this my attempt at batch but the var doesnt work



for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


this code works fine



 for i in *.mp4;  
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


Got it working with these 2 commands did the whole batch in one script



 for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


for i in *.mp4;
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


thank you










share|improve this question









New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

    – Ben Owen
    Jan 22 at 19:40











  • Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

    – Ben Owen
    Jan 22 at 21:35













  • 848x480 please as the 1.mp4 the main file

    – Ben Owen
    2 days ago











  • Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

    – llogan
    2 days ago











  • pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

    – Ben Owen
    yesterday
















1















Hi sorry if this has already been asked but ive got intro.mp4 and over 1000 mp4 in another folder what i need is intro.mp4 to be added to every mp4 in folder im using ubuntu whats the best way to do this.



all the mp4 have the same encoding



ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy output.mp4


this command words for one at a time
this my attempt at batch but the var doesnt work



for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


this code works fine



 for i in *.mp4;  
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


Got it working with these 2 commands did the whole batch in one script



 for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


for i in *.mp4;
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


thank you










share|improve this question









New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

    – Ben Owen
    Jan 22 at 19:40











  • Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

    – Ben Owen
    Jan 22 at 21:35













  • 848x480 please as the 1.mp4 the main file

    – Ben Owen
    2 days ago











  • Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

    – llogan
    2 days ago











  • pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

    – Ben Owen
    yesterday














1












1








1








Hi sorry if this has already been asked but ive got intro.mp4 and over 1000 mp4 in another folder what i need is intro.mp4 to be added to every mp4 in folder im using ubuntu whats the best way to do this.



all the mp4 have the same encoding



ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy output.mp4


this command words for one at a time
this my attempt at batch but the var doesnt work



for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


this code works fine



 for i in *.mp4;  
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


Got it working with these 2 commands did the whole batch in one script



 for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


for i in *.mp4;
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


thank you










share|improve this question









New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Hi sorry if this has already been asked but ive got intro.mp4 and over 1000 mp4 in another folder what i need is intro.mp4 to be added to every mp4 in folder im using ubuntu whats the best way to do this.



all the mp4 have the same encoding



ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy output.mp4


this command words for one at a time
this my attempt at batch but the var doesnt work



for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


this code works fine



 for i in *.mp4;  
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


Got it working with these 2 commands did the whole batch in one script



 for f in *.mp4; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -f mpegts "$f.ts"; done


for i in *.mp4;
do
test="concat:intro.mp4.ts|"${i%.*}".mp4.ts";
ffmpeg -i "$test" -c copy anime2/"${i%.mp4}.mp4"; done


thank you







ffmpeg mp4






share|improve this question









New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday







Ben Owen













New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Jan 22 at 14:24









Ben OwenBen Owen

113




113




New contributor




Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ben Owen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

    – Ben Owen
    Jan 22 at 19:40











  • Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

    – Ben Owen
    Jan 22 at 21:35













  • 848x480 please as the 1.mp4 the main file

    – Ben Owen
    2 days ago











  • Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

    – llogan
    2 days ago











  • pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

    – Ben Owen
    yesterday



















  • codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

    – Ben Owen
    Jan 22 at 19:40











  • Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

    – Ben Owen
    Jan 22 at 21:35













  • 848x480 please as the 1.mp4 the main file

    – Ben Owen
    2 days ago











  • Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

    – llogan
    2 days ago











  • pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

    – Ben Owen
    yesterday

















codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

– Ben Owen
Jan 22 at 19:40





codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope

– Ben Owen
Jan 22 at 19:40













Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

– Ben Owen
Jan 22 at 21:35







Hi please check this paste bin pastebin.com/ci5ADeX2 first 3 lines i tried worked perfectly my attempt to turn it in to batch not so much the variable doesn't seem to show no matter how i label it and at the bottom is the information you requested

– Ben Owen
Jan 22 at 21:35















848x480 please as the 1.mp4 the main file

– Ben Owen
2 days ago





848x480 please as the 1.mp4 the main file

– Ben Owen
2 days ago













Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

– llogan
2 days ago





Please show the output of ffprobe -v error -show_streams 1.mp4. I should have asked for that previously instead of the ffmpeg output.

– llogan
2 days ago













pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

– Ben Owen
yesterday





pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?

– Ben Owen
yesterday










1 Answer
1






active

oldest

votes


















1














The parameters must match so first you must conform the intro to match the other videos (or vice versa).



Use ffprobe to view differences:



ffprove -loglevel error -show_streams intro.mp4
ffprove -loglevel error -show_streams 1.mp4


Re-encode intro.mp4 to match 1.mp4:



ffmpeg -i intro.mp4 -filter_complex "[0:v]fps=500/21,scale=848:480:force_original_aspect_ratio=increase,crop=848:480,setsar=171/170[v]" -map "[v]" -map 0:a -c:v libx264 -profile:v main -c:a aac -ar 44100 intro_b.mp4


Now use the concat demuxer. Make a text file listing inputs to be concatenated:



file 'intro_b.mp4'
file '1.mp4'


Then concatenate:



ffmpeg -f concat -i input.txt -c copy output.mp4





share|improve this answer


























  • using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

    – Ben Owen
    yesterday











  • @BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

    – llogan
    yesterday













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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
});


}
});






Ben Owen is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1111975%2fffmpeg-merge-mp4-to-mp4-batch%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














The parameters must match so first you must conform the intro to match the other videos (or vice versa).



Use ffprobe to view differences:



ffprove -loglevel error -show_streams intro.mp4
ffprove -loglevel error -show_streams 1.mp4


Re-encode intro.mp4 to match 1.mp4:



ffmpeg -i intro.mp4 -filter_complex "[0:v]fps=500/21,scale=848:480:force_original_aspect_ratio=increase,crop=848:480,setsar=171/170[v]" -map "[v]" -map 0:a -c:v libx264 -profile:v main -c:a aac -ar 44100 intro_b.mp4


Now use the concat demuxer. Make a text file listing inputs to be concatenated:



file 'intro_b.mp4'
file '1.mp4'


Then concatenate:



ffmpeg -f concat -i input.txt -c copy output.mp4





share|improve this answer


























  • using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

    – Ben Owen
    yesterday











  • @BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

    – llogan
    yesterday


















1














The parameters must match so first you must conform the intro to match the other videos (or vice versa).



Use ffprobe to view differences:



ffprove -loglevel error -show_streams intro.mp4
ffprove -loglevel error -show_streams 1.mp4


Re-encode intro.mp4 to match 1.mp4:



ffmpeg -i intro.mp4 -filter_complex "[0:v]fps=500/21,scale=848:480:force_original_aspect_ratio=increase,crop=848:480,setsar=171/170[v]" -map "[v]" -map 0:a -c:v libx264 -profile:v main -c:a aac -ar 44100 intro_b.mp4


Now use the concat demuxer. Make a text file listing inputs to be concatenated:



file 'intro_b.mp4'
file '1.mp4'


Then concatenate:



ffmpeg -f concat -i input.txt -c copy output.mp4





share|improve this answer


























  • using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

    – Ben Owen
    yesterday











  • @BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

    – llogan
    yesterday
















1












1








1







The parameters must match so first you must conform the intro to match the other videos (or vice versa).



Use ffprobe to view differences:



ffprove -loglevel error -show_streams intro.mp4
ffprove -loglevel error -show_streams 1.mp4


Re-encode intro.mp4 to match 1.mp4:



ffmpeg -i intro.mp4 -filter_complex "[0:v]fps=500/21,scale=848:480:force_original_aspect_ratio=increase,crop=848:480,setsar=171/170[v]" -map "[v]" -map 0:a -c:v libx264 -profile:v main -c:a aac -ar 44100 intro_b.mp4


Now use the concat demuxer. Make a text file listing inputs to be concatenated:



file 'intro_b.mp4'
file '1.mp4'


Then concatenate:



ffmpeg -f concat -i input.txt -c copy output.mp4





share|improve this answer















The parameters must match so first you must conform the intro to match the other videos (or vice versa).



Use ffprobe to view differences:



ffprove -loglevel error -show_streams intro.mp4
ffprove -loglevel error -show_streams 1.mp4


Re-encode intro.mp4 to match 1.mp4:



ffmpeg -i intro.mp4 -filter_complex "[0:v]fps=500/21,scale=848:480:force_original_aspect_ratio=increase,crop=848:480,setsar=171/170[v]" -map "[v]" -map 0:a -c:v libx264 -profile:v main -c:a aac -ar 44100 intro_b.mp4


Now use the concat demuxer. Make a text file listing inputs to be concatenated:



file 'intro_b.mp4'
file '1.mp4'


Then concatenate:



ffmpeg -f concat -i input.txt -c copy output.mp4






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









lloganllogan

5,0551535




5,0551535













  • using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

    – Ben Owen
    yesterday











  • @BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

    – llogan
    yesterday





















  • using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

    – Ben Owen
    yesterday











  • @BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

    – llogan
    yesterday



















using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

– Ben Owen
yesterday





using your way, how would i batch it for 1000 other mp4 files i have to add it to? Thank you

– Ben Owen
yesterday













@BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

– llogan
yesterday







@BenOwen You're encouraged to ask only one question per post on Stack Exchange. Yours is two questions in one: 1) how to concatenate arbitrary videos of different parameters (which this answer addresses), and 2) how to perform a batch operation. These are two very different questions. I may update this later to address both questions, but if not then I recommend editing your original question to only be about question #1, and make a new post regarding #2.

– llogan
yesterday












Ben Owen is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Ben Owen is a new contributor. Be nice, and check out our Code of Conduct.













Ben Owen is a new contributor. Be nice, and check out our Code of Conduct.












Ben Owen is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1111975%2fffmpeg-merge-mp4-to-mp4-batch%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

Category:香港粉麵

List *all* the tuples!

Channel [V]