i have a couple of videos and i want to make them smaller to save some space... therefore i really would like to merge the audiotracks of file1 into file2
so that i can later on delete file1 because the picture content of both videos is the same...
Is there a way to accomplish that with ffmpeg? With this cmd i would have 2 video/audio tracks in one file so this is NOT what i want.
ffmpeg -i file1.mp4 -i file2.mp4 -c copy output.mp4
i only want the audio of file1 and the video and audio of file2 merge into one file...
Thanks
You need to use the map option:
ffmpeg -i file1.mp4 -i file2.mp4 -map 1 -map 0:a -c copy output.mp4
This selects all streams from the 2nd input and the audio streams from the first.
BTW, your command wouldn't have copied both audio and video tracks; only one audio and video from among both inputs. See https://ffmpeg.org/ffmpeg.html#Stream-selection
Related
I have an FFMPEG question for you!
Problem:
I have 2 files(x265)
01.mkv with multiple audio steams and multiple subtitles (with exactly named layers)
02.mkv with multiple audio steams and multiple subtitles (with exactly named layers)
I would like to add specific audio layer(GER) and specific subtitle(GER)
from 02.mkv to 01 mkv at the same time if it is possible.
(The metadata positions almost always random in file 02.mkv so I can't say it is "-map 0:s:2 for ger subtitle"...)
I have already searched and tried multiple solutions ...
This kind of worked with multiple steps but loses audio and subtitle metadata(Title) during process.
German audio layer extract from 02.mkv to aac
ffmpeg -i 02.mkv -map 0:a:m:language:ger 02.aac
German subtitle layer extract from 02.mkv to srt
ffmpeg -i 02.mkv -map 0:s:m:language:ger 02.srt
Adding extracted audio to 01.mkv
ffmpeg -i 01.mkv -i 02.aac -map 0 -map 1 -codec copy outputfinall_1.mkv
Adding extracted srt to 01.mkv none of this works
1.)
ffmpeg -i 01.mkv -i 02.srt -c copy -c:s mov_text outputfinall_2a.mkv
BUG: Subtitle encoding currently only possible from text to text or bitmap to bitmap
2.)
ffmpeg -i 01.mkv -i 02.srt -map 0 -map 1 -codec copy outputfinall_2b.mkv
works but does not show subtitles while playing only that is there.
Please if you can help I would like a less jumbled mess code for this problem.
With keeping the metadata (titles) of the moved audio stream and subtitle.
Thank you for your time!
Try this:
ffmpeg -i 01.mkv -i 02.mkv \
-map 0 -map 1:a:m:language:ger -map 1:s:m:language:ger \
-c copy outputfinall.mkv
I'm not sure what you mean by "metadata (titles)", posting the log of the above command with clarification will help understanding your situation.
What I want to achieve
I have two input videos which I do want to concatenate using ffmpeg.
Issue
The input videos contain two stereo audio channels:
after concatenation, the second audio stream is lost:
steps to reproduce
The Command I used is
ffmpeg -f concat -i list.txt -c:a copy -c:v copy demuxed.mp4
Additional Information
The Console Output shows the second audio stream in input properly:
The Output settings also show that there is only one audio output stream. But I want to have the exact same settings in to out, just concatenated:
Assuming that all input videos have matching audio streams, add mapping.
ffmpeg -f concat -i list.txt -map 0:v -map 0:a -c:a copy -c:v copy demuxed.mp4
See http://ffmpeg.org/ffmpeg.html#Stream-selection, especially the section on automatic stream selection for details on how ffmpeg selects streams.
I am trying to join 2-3 videos it's working when all video has audio or without audio...
Command= "-f concat -i files.txt -codec copy output.mp4"
File.txt
file '0.mp4'
file '1.mp4'
file '2.mp4'
Now the issue is when 0.mp4 is without audio and 1.mp4 is with audio and when i join these videos full audio lost in output.. output will be without audio.
I want this join with all as it is like if 0.mp4 without audio then audio will not play for this and 1.mp4 play audio should play...
Finally got the answer.. need to first add silent audio in video files that don't have audio
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i 0.mp4 -shortest -c:v copy -c:a aac new_0.mp4
From here I concatenate as I did before, but replacing "0.mp4" in
File.txt with "new_0.mp4"
File.txt
file 'new_0.mp4'
file '1.mp4'
file '2.mp4'
Command= "-f concat -i files.txt -codec copy output.mp4"
I'm looking for a solution in FFmpeg to merge audio (mp3) with a short video loop, or gif.
I've already been able to generate a video from an image by joining with audio, but the video stays static frame for the audio duration, the command to make this:
ffmpeg -loop 1 -i imagem.jpg -i audio.mp3 -vcodec h264 -tune stillimage -acodec aac -b:a 64k -pix_fmt yuv420p -shortest video.mp4
I need video that has the duration of the audio, but that uses a loop of another mp4 or a gif. To keep repeating for the duration of the audio.
To do this with a video (MP4 or other format) you should use the Concatenate demuxer.
First create a text file with a list of the paths of the videos you want to concatenate. In your case it will be a list of the same video file, like the following.
# mylist.txt
file /your/path/video.mp4
file /your/path/video.mp4
file /your/path/video.mp4
The paths can be absolute or relative.
Then you need to use the concat demuxer option.
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
This will generate an mp4 with your original video looping 3 times. If your original video is 4 seconds long, then the output will be 12 seconds long. I suggest that you create a video just a bit longer than your audio track and then use the -shortest option when creating your final video.
You can add the audio within this same command like you do in your post. So, all together will look like this:
ffmpeg -f concat -safe 0 -i mylist.txt -i audio.mp3 -c:v copy -c:a copy -shortest output.mp4
In my example I do a stream copy for my output (this will work just fine and will be very fast), but you can use the codecs you want for yours (like H264 and AAC like your post).
You can find more info in the concat demuxer documentation or better yet the concat wiki.
At the moment I don't know if there's a way to do this with a gif file.
I am trying to cut a video in 2 parts then reassembling with ffmpeg but the final output has a small audio glitch right where the segments meet. I am using the following command to split the video 1.mp4 in 2 parts:
ffmpeg -i 1.mp4 -ss 00:00:00 -t 00:00:02 -async 1 1-1.mp4
and
ffmpeg -i 1.mp4 -ss 00:00:02 -t 00:00:02 -async 1 1-2.mp4
Once I have the 2 parts I am concatening them back together with:
ffmpeg -f concat -i files.txt -c copy output.mp4
files.txt is correctly listing both files. Can anyone point me to where the problem might be?
Thanks
The glitch is likely due to the audio priming sample showing up in between.
Since you're re-encoding the segments, you can do this in one command:
ffmpeg -i 1.mp4 -filter_complex
"[0]trim=duration=2[v1];[0]trim=2:4,setpts=PTS-STARTPTS[v2];
[0]atrim=duration=2[a1];[0]atrim=2:4,asetpts=PTS-STARTPTS[a2];
[v1][a1][v2][a2]concat=n=2:v=1:a=1[v][a]"
-map "[v]" -map "[a]" output.mp4
I had the same problem for about 3 weeks.
just merge the mp3 files using sox
sox in1.mp3 in2.mp3 in3.mp3 out.mp3
When I used concat with FFMPEG it made 12.5ms (I saw them on using Audacity) audio gaps. (I don't know why)
Maybe for your case it'll be better to extract the audio and video to two separate files using ffmpeg, merge them (video using FFMPEG and audio using sox) then put the files together into one container (mp4) file