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

7
  • codec - yes, width - yes height- yes, pixel format -not sure, - timebase- nope audio-nope
    – Ben Owen
    Jan 22, 2019 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, 2019 at 21:35
  • 848x480 please as the 1.mp4 the main file
    – Ben Owen
    Jan 23, 2019 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, 2019 at 20:25
  • pastebin.com/X2GxNUWd is there no hope for my attempt at a batch?
    – Ben Owen
    Jan 24, 2019 at 19:06

1 Answer 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
2
  • 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, 2019 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, 2019 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .