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

























  • 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
    Jan 23 at 10:20











  • 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
    Jan 23 at 20:25











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

    – Ben Owen
    Jan 24 at 19:06
















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

























  • 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
    Jan 23 at 10:20











  • 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
    Jan 23 at 20:25











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

    – Ben Owen
    Jan 24 at 19:06














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
















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















share|improve this question













share|improve this question




share|improve this question








edited Jan 24 at 19:33







Ben Owen

















asked Jan 22 at 14:24









Ben OwenBen Owen

113




113













  • 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
    Jan 23 at 10:20











  • 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
    Jan 23 at 20:25











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

    – Ben Owen
    Jan 24 at 19:06



















  • 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
    Jan 23 at 10:20











  • 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
    Jan 23 at 20:25











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

    – Ben Owen
    Jan 24 at 19:06

















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
Jan 23 at 10:20





848x480 please as the 1.mp4 the main file

– Ben Owen
Jan 23 at 10:20













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
Jan 23 at 20:25





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
Jan 23 at 20:25













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

– Ben Owen
Jan 24 at 19:06





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

– Ben Owen
Jan 24 at 19:06










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
    Jan 24 at 19:54











  • @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
    Jan 24 at 19:57













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
});


}
});














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
    Jan 24 at 19:54











  • @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
    Jan 24 at 19:57


















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
    Jan 24 at 19:54











  • @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
    Jan 24 at 19:57
















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 Jan 24 at 19:53

























answered Jan 24 at 19:44









lloganllogan

5,1701536




5,1701536













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

    – Ben Owen
    Jan 24 at 19:54











  • @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
    Jan 24 at 19:57





















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

    – Ben Owen
    Jan 24 at 19:54











  • @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
    Jan 24 at 19:57



















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

– Ben Owen
Jan 24 at 19:54





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

– Ben Owen
Jan 24 at 19:54













@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
Jan 24 at 19:57







@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
Jan 24 at 19:57




















draft saved

draft discarded




















































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

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?