Can not hear audio when concatenate some mp4 files using FFMPEG [duplicate] - ffmpeg

This question already has answers here:
How to add a new audio (not mixing) into a video using ffmpeg?
(10 answers)
Closed 4 years ago.
I need to concatenate some MP4 files. Only one of them has audio. The other ones hasn't.
MyList.txt contains:
file1.mp4 without audio and 5s length
File2.mp4 without audio and 5s length
File3.mp4 without audio and 5s length
File4.mp4 with audio and Ns length
I need an output that cotains the 4 mp4 files and when file4.mp4 starts I want to hear its audio.
If I set the file4.mp4 as the first video to concat, the output video has audio, but If I set the file4.mp4 in another position, the output video hasn't audio.
What I'm doing wrong? What I have to modify in my code?
ffmpeg -f concat -safe 0 -i myList.txt -c:v copy -c:a copy output.mp4

Have you tried generating a silent track for your mp4 files without any sound and then concatenating them?
ffmpeg -i "clip.mp4" -f lavfi -i aevalsrc=0 -shortest -y "new_clip.mp4"
This does the following:
Take clip.mp4 (which is the video clip without audio) (-i "clip.mp4")
Generate the minimum silence required (-f lavfi -i aevalsrc=0
-shortest)
Output the result (-y "new_clip.mp4")
Same problem but asked on stack exchange:
Link
Broader explanation can be found here:
second link

Related

Concatenating/Splicing overlapping video clips with ffmpeg

I'm trying to concatenate multiple short .mp4 video clips from a security camera. The camera records short clips, with a few seconds on either end of a timespan when motion is detected. For example, two minutes of video will often be broken up into four ~35 second clips, with the first/last few seconds of each clip being duplicative of the last/first few seconds of the previous/next clip.
I simply concatenate the clips together using the ffmpeg concat demuxer, as described here: How to concatenate two MP4 files using FFmpeg?, with
(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
Or else I transcode them into intermediate MPEG-2 transport streams, which I can then concatenate with the file-level concat protocol, as described here: https://trac.ffmpeg.org/wiki/Concatenate#protocol, with
ffmpeg -i "first file.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i "second file.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
But either way, the resulting video (output.mp4) jumps backward in time a few seconds every half-minute or so because of the duplicated frames.
I want to throw out the duplicate frames, and tie the clips together based on timestamps to achieve smooth playback of the concatenated full-length video. I'd strongly prefer to do this on Windows with ffmpeg if possible. Surely this has been done before, right? Are there timestamps in the .mp4 files that I can use to determine how much overlap there is, and then splice at the proper point-in-time? And if so, how do I read them, how do I splice at an exact point in time, and how do I get around the KeyFrames issue if I can splice at the exact point in time?

how to create a radio or video "station" continuous TS stream with ffmpeg

I can't find any answer to this scenarios:
Produce a continuous ts file that initially contains silence (or blank video), and as I add files to a text file I wish them to be queued in the output ts stream.
Think of it as a radio or tv station.
I found everything on how to stream anything to anything,
but not a tv/radio broadcast like stream.
A good start seems to be this:
ffmpeg -re -y -nostats -nostdin -hide_banner -loglevel quiet -fflags +genpts -f concat -i list.txt -map 0:a? -map 0:v? -map 0:s? -strict -2 -dn -c copy -hls_flags delete_segments -hls_time 10 -hls_list_size 6 /var/www/html/showname_.m3u8
list.txt example
file '/mnt/vusolo-tv/show/Season 1/S01E01.mp4'
file '/mnt/vusolo-tv/show/Season 1/S01E02.mp4'
But i think there can be better ways...
This is not a good answer either: From multiple video files to single output
because "All files must have streams with identical encoding. Timebase for streams should be the same. Duration of all streams within a file should be the same, in order to maintain sync."
And I want to be able to add arbitrary files and produce a TS stream playable by any TV (once broadcasted in dvb).

How to split video by duration like 10sec in FFmpeg? [duplicate]

This question already has answers here:
How to split a video using FFMPEG so that each chunk starts with a key frame?
(6 answers)
record desktop save every 30 minutes
(2 answers)
Export each minute of MP3 into separate WAV
(1 answer)
How to get equally spaced audio chunks from .wav file using ffmpeg?
(1 answer)
How to segment a video and then concatenate back into original one with ffmpeg
(1 answer)
Closed 4 years ago.
I am new in ffmpeg! i want to split videos which duration like 3 mins. or more into 10 sec.using ffmpeg?
please help me how to resolve it.
Use these commands in sequence for splitting videos.
ffmpeg -ss 00:00:00 -t 10 -i input.mov -vcodec copy -acodec copy output_part1.mov
ffmpeg -ss 00:00:10 -t 10 -i input.mov -vcodec copy -acodec copy output_part2.mov
ffmpeg -ss 00:00:20 -t 10 -i input.mov -vcodec copy -acodec copy output_part3.mov
ffmpeg -ss 00:00:30 -t 10 -i input.mov -vcodec copy -acodec copy output_part4.mov
-ss stands for start time,
-t is the length of final clip,
-i is the input file, in this case it's a file called 'input.mov'
-vcodec is the video codec used to encode the output file. 'copy' means we're using the
same codec as the input file.
-acodec is the audio codec. Like the video codec, we'll be using the same audio codec as the input file.
output.mov is the output file, you can rename this to any file name you choose.

Trying to concatenate very large video files with ffmpeg

I have about anywhere from 10-24 mp4 files that are about 1 hour in length each and when I try to concatenate them into one I am only left with a 1 hour output.mp4 where its only content is of that of the first 1 hour video I fed in with the audio completely choppy.
Has anyone tried to run ffmpeg to form a very large video file?
This is one of the ffmpeg commands I ran
ffmpeg -f concat -safe 0 -i videos.txt -an -filter:v "setpts=0.01*PTS" total_output.mkv

Add multiple audio files to video at specific points using FFMPEG

I am trying to create a video out of a sequence of images and various audio files using FFmpeg. While it is no problem to create a video containing the sequence of images with the following command:
ffmpeg -f image2 -i image%d.jpg video.mpg
I haven't found a way yet to add audio files at specific points to the generated video.
Is it possible to do something like:
ffmpeg -f image2 -i image%d.jpg -i audio1.mp3 AT 10s -i audio2.mp3 AT 15s video.mpg
Any help is much appreciated!
EDIT:
The solution in my case was to use sox as suggested by blahdiblah in the answer below. You first have to create an empty audio file as a starting point like that:
sox -n -r 44100 -c 2 silence.wav trim 0.0 20.0
This generates a 20 sec empty WAV file. After that you can mix the empty file with other audio files.
sox -m silence.wav "|sox sound1.mp3 -p pad 0" "|sox sound2.mp3 -p pad 2" out.wav
The final audio file has a duration of 20 seconds and plays sound1.mp3 right at the beginning and sound2.mp3 after 2 seconds.
To combine the sequence of images with the audio file we can use FFmpeg.
ffmpeg -i video_%05d.png -i out.wav -r 25 out.mp4
See this question on adding a single audio input with some offset. The -itsoffset bug mentioned there is still open, but see users' comments for some cases in which it does work.
If it works in your case, that would be ideal:
ffmpeg -i in%d.jpg -itsoffset 10 -i audio1.mp3 -itsoffset 15 -i audio2.mp3 out.mpg
If not, you should be able to combine all the audio files with sox, overlaying or inserting silence to produce the correct offsets and then use that as input to FFmpeg. Not as convenient, but guaranteed to work.
One approach I can think of is to create your audio file for the whole duration of the video first and then mux the audio with the video file

Resources