how to loop audio to a ffmpeg generated video - ffmpeg

i am a beginner programmmer and am trying to implement ffmpeg. I am trying to convert a bunch of images to video and add a audio background. Can anybody help me and tell me how to loop the audio as required by the length of the video generated.
PS. This number of images varies so can we implement something that dynamically loops the audio as required

Use
ffmpeg -i images%d.jpg -f lavfi -i amovie=audio.mp3:loop=0,asetpts=N/SR/TB -shortest out.mp4

Related

ffmpeg: concatenating mp4 files. Video freezes for few seconds on first frame on output mp4

I created several MP4 files using ffmpeg. All of the videos have same settings and codec. Only difference is frames per second and duration. I then concatenated the videos using command below.
ffmpeg -f concat myList.txt -c copy output.mp4
I notice that when launching/opening the output.mp4 file in windows media player, it stops/freezes on the first frame of the video for about three four seconds and then starts playing, rest of the videos has correct fps and runs smoothly. Has anyone encountered this issue. I would like the video to start as soon as it is launched. Any suggestions to mitigate this issue?
Update: So far, I have found that the video length is exactly what I expect it to be.
ffprobe -i output.mp4
When i ffplay the video, it runs smoothly, but when I use windows media player, it gets stuck in first frame for about 4-5 seconds then plays smoothly. So I am going to assume that this issue is related to media players (buffers/loading before playing). Can't be sure though.
I solved this problem by converting my input files to avi and resizing them to the same size.
And then run
ffmpeg -i "concat:file1.avi|file2.avi|" -c copy out.avi

FFMPG Concat two video quality issue

I'm trying to concat two mp4 video files using ffmpg (with the below command), a main video and a secondary one, the main video always have 1080x1920 resolution and the resulting video should have the some resolution.
val concat = "-i ${mainVideoPath} -i ${secondVideoPath} -filter_complex [0:v]scale=1080:1920:force_original_aspect_ratio=decrease,setsar=1:1,pad=1080:1920:(ow-iw)/2:(oh-ih)/2[s0];[1:v]scale=1080:1920:force_original_aspect_ratio=decrease,setsar=1:1,pad=1080:1920:(ow-iw)/2:(oh-ih)/2[s1];[s0][s1]concat=n=2:v=1[v] -map [v] $resultVideoPath"
The concat work fine but the main part of my resulting video always lose quality although the resulting video has the same resolution.
Any help will be appreciated.

Multiple side-to-side video streams in one file without transcoding

I am investigating a possibility to store video streams which are coming from few sources already coded in h264 without video transcoding as the device I would like to use for this project won't be capable of transcoding combined video on the fly.
What I am looking for is two or more pictures side to side (not video concatenation) packed into mp4/avi/mkv.
I believe mkv container supports such kind of packaging but I've not been able to find appropriate options for ffmpeg or other tool to store it this way. What it does is very slow video transcoding into one big h264 stream.
If your player can handle it just make it perform the side-by-side view. No encoding or muxing required.
mpv video player
Example using mpv:
mpv --lavfi-complex="[vid1][vid2]hstack[vo];[aid1][aid2]amix[ao]" input1.mp4 --external-file=input2.mp4
The above example assumes each input has the same height. Otherwise you will have to add the scale, scale2ref, pad, and/or crop filters. Simple example using the crop filter to remove 20 pixels from the height:
mpv --lavfi-complex="[vid1]crop=iw:ih-20[c];[c][vid2]hstack[vo];[aid1][aid2]amix[ao]" input1.mp4 --external-file=input2.mp4
See the mpv documentation and FFmpeg Filters for more info.
Just specify multiple inputs.
ffmpeg -i [input 1] -i [input 2] ... -map 0 -map 1 ... -codec copy -f matroska [output]
As for the "side-to-side" part, it's up to the player to determine the presentation. If you don't control the player and you need a specific layout or presentation, then you must "burn" all these video streams into a new one and encode it as a new single stream.

FFmpeg Video First Frame Time Code value

I would like to ask someone how knows FFmpeg good
As you can see I already know how to set timecodes that contain in green borders,
but I don't know is there any opportunity set the Video timecode.
Thank you for you help
Only possible with ffmpeg if you are ready to re-encode the video stream as MPEG-2 e.g.
ffmpeg -i input -c:v mpeg2video -gop_timecode "03:04:05:06" output

FFmpeg Images to Video and Streaming

I've a C# program generating JPEG images in realtime, i need to (continuously) generate a video from the images and stream it (also in realtime).
I've used ffmpeg to transcode an input video source and stream it, doesn't ffmpeg have an option to get the input as a set of images(always being generated) and make the video out of it ?
Cheers
Actually I used VLC for the streaming....
Actually I just found at that I could:
ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
But i need to tell ffmpeg to keep doing it, I mean, if it doesn't find another image ffmpeg should wait for another one to be generated... is this possible ?

Resources