0

After a lot of research and testing, I wrote a command that I can adapt for multiple sources to be concatenated using FFMPEG. I'm running into a problem though with add looped images (as videos) into the concatenation.

Here's the command:

ffmpeg -y -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
ffmpeg -y -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
ffmpeg -y -f lavfi -i anullsrc  -loop 1 -f image2 -i input3.jpg -r 30 -t 3 -pix_fmt yuvj420p -map 0:a -map 1:v -f mpegts temp3 2> /dev/null & \
ffmpeg -y -f mpegts -i "concat:temp1|temp2|temp3" -bsf:a aac_adtstoasc out.mp4

The end result should be 2 videos, then an image looped for 3 seconds (with no audio), all concatenated into a long video. Instead, all I get is a single concatenated video that contains the first two videos, but not the image looped.

  • Here's the output from FFMPEG: d.pr/n/1aHGB – Daniel Jacob Archer Dec 4 '15 at 20:02
  • Please show the complete console output of: ffmpeg -i input1.mp4 -i input2.mp4 -i input3.jpg – llogan Dec 4 '15 at 20:54
  • @LordNeckbeard what do you hope for with that command? It's only inputs - do you mean ffmpeg concat with those inputs? – Daniel Jacob Archer Dec 4 '15 at 21:06
  • I want to see all of the info about the inputs. I suspect they need some work before being concatenated. – llogan Dec 4 '15 at 21:08
  • Ah ok. Here's the output: d.pr/n/19Dgv – Daniel Jacob Archer Dec 4 '15 at 21:08
0

It appears your script backgrounds the first 3 commands, so your script runs the commands at virtually the same time. There is no guarantee commands 1-3 will complete before the 4th concatenates their output. Removing trailing ampersands and backslashes will cause the script to wait for each command to complete before starting the next. If each command uses most of the i/o bandwidth, then this change will not slow your script much. Otherwise, here is a method to run the first 3 commands in the background but to wait until they're done to run the 4th (untested).

{ ./prog1 ; ./prog2 ; ./prog3 ; } && ./prog4
  • I'm actually closely following FFMPEG's Concatenate documentation, so I don't know that it should be written like you suggested... Also your proposed solution would require writing scripts for each command. – Daniel Jacob Archer Dec 9 '15 at 0:33
  • I did not intend to suggest that more 'progs' would be necessary. "prog1", for example, is a placeholder for "ffmpeg -y -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1". (You would /not/ need to make more commands.) My overall point was to explore the job control inherent in bash, e.g. backgrounding jobs and its implications. I don't have the ffmpeg docs, but I do think that if you try the code snippet (of course inserting your ffmpeg commands in full instead of "prog1", e.g.) you may be pleasantly surprised. Good luck to you. – Erik Bryer Dec 9 '15 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.