For the first bullet point I don't see a direct command. What I'm suggesting is to use ffprobe
to calculate the duration of both files and calculate the number of video loops that need to play for the duration of audio.
Following will result the duration of the inputs.
ffprobe -i input_media -show_entries format=duration -v quiet -of csv="p=0"
Then you can loop the video manually until you satisfy the calculated value of video instances.
ffmpeg -i input_audio -f concat -i <(for i in {1..n}; do printf "file '%s'\n" input_video; done) -c:v copy -c:a copy -shortest output_video
1..n
stands for the number of times the video need to be looped. Instead of -shortest
you can use -t
as you have already calculated the duration of the audio.
Following is the associated shell script.
#!/bin/bash
audio_duration=$(ffprobe -i ${1} -show_entries format=duration -v quiet -of csv="p=0")
video_duration=$(ffprobe -i ${2} -show_entries format=duration -v quiet -of csv="p=0")
n_loops=$(echo "(${audio_duration} / ${video_duration}) + 1"|bc)
ffmpeg -i ${1} -f concat -i <(for i in {1..${n_loops}}; do printf "file '%s'\n" ${2}; done) -c:v copy -c:a copy -shortest ${3}
For windows you can convert this shell script to a batch script.
More information:
Hope this helps!