I have a MKV file with a H264 video track, FLAC audio track and ASS subtitle track. I want to convert the file to a MP4 but keep the video track and re-encode the audio and subtitle tracks. How do I do that?
Use the -c/-codec and -map options.
ffmpeg -i input.mkv -map 0 -c:v copy -c:a aac -c:s mov_text output.mp4
copy enables stream copy mode which only re-muxes and does not re-encode (the video in this example).
See the ffmpeg documentation for more info.
Related
I have two videos of the same length that I'd like to combine. Video A has audio, video B does not. I'd like to take the audio from video A and put it onto Video B. I'd like to do this with FFMPEG, but I can't figure out the arguments I need? Should I use map?
There's a lot of questions about combining a video with audio, but not two videos.
Do I maybe need an intermediate step of converting my original video to audio?
I have tried using this FFMPEG command, and a couple of variations. All of the resulted in just Video A (the one with audio) being the output.
ffmpeg -i videoB.mp4 -i video A.mp4 -c:v copy -c:a aac output.mp4
Try this as a starter
ffmpeg -i videoB.mp4 -i video A.mp4
-filter_complex [0:v][1:a][1:v][1:a]concat=n=2:v=1:a=1[vout][aout]
-map [vout] -map [aout] -c:v h264 -c:a aac output.mp4
You must reencode though.
How can I create a MP4 file with ffmpeg out of a M2V-Video-File and two WAV-Files (one file for the right audio channel and one for the left audio channel)?
try this:
ffmpeg -i video.m2v -i audio1.wav -i audio2.wav -c:v copy -c:a aac -map 0:v:0 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" output.mp4
I believe mp4 files cannot contain PCM audio, hence converting to aac.
I have some DVDs that I would like to encode so that I can play them on a Chromecast, with subtitles. It seems that Chromecast only supports text-based subtitle formats, while DVD subtitles are in a bitmap format, so I need to hardcode the subtitles onto the video stream.
First I use vobcopy to create a VOB file:
vobcopy -I /dev/sr0
Next I want to use ffmpeg to encode it as a video stream in a format that is supported by the Chromecast. This is the closest I've come so far (based on the ffmpeg documentation):
ffmpeg -analyzeduration 100M -probesize 100M -i in.vob \
-filter_complex "[0:v:0][0:s:0]overlay[vid]" -map "[vid]" \
-map 0:3 -codec:v libx264 -crf 20 -codec:a copy out.mkv
The -filter_complex "[0:v:0] [0:s:0]overlay[vid] parameters should overlay the first subtitle stream on the first video stream (-map 0:3 is for the audio). This partially works, but the subtitles are only shown for a fraction of a second (I'm guessing one frame).
How can I make the subtitles display for the correct duration?
I'm using ffmpeg 4.4.1 on Linux, but I've also tried the latest snapshot version, and tried gstreamer and vlc (but didn't get far).
The only solution I found that worked perfectly was a tedious multi-stage process.
Copy the DVD with vobcopy
vobcopy -I /dev/sr0
Extract the subtitles in vobsub format using mencoder. This command will write subs.idx and subs.sub. The idx file can be edited if necessary to tweak the appearance of the subtitles.
mencoder *.vob -nosound -ovc frameno -o /dev/null \
-vobsuboutindex 0 -sid 0 -vobsubout subs
Copy the audio and video from the VOB into an mkv file. ffprobe can be used to identify the relevant video and audio stream numbers.
ffmpeg -fflags genpts -i *vob -map 0:1 -map 0:3 \
-codec:v copy -codec:a copy copied_av.mkv
Merge the subtitles with the audio/video stream.
mkvmerge -o merged.mkv copied_av.mkv subs.sub subs.idx
Then ffmpeg will work reliably with the mkv file to write hardcoded subtitles to the video stream.
ffmpeg -i merged.mkv -filter_complex "[0:v:0][0:s:0]overlay[vid]" \
-map [vid] -map 0:1 -codec:v libx264 -codec:a copy hardcoded.mkv
It might be a duplicate question but didn't find any helpful answer.
I have 2 audio files and 1 mp4 video file. Want to add the 2 audio files to mp4 videoat specific time.
For example:
Video file:
input.mp4 (2 minutes video)
Audio files:
Audio File 1:
test_0:01.mp3 (15 seconds audio file) I want to insert this file at position 0:01 in the mp4 video
Audio File 2:
test_0:20.mp3(15 seconds audio file) I want to insert this file at position 0:20 in the mp4 video
I tried the following command with offset
It's only inserting test_0:01.mp3 at 0:01 position in the video file
But test_0:20.mp3 is not getting inserted at 0:020 position getting mute for this file no audio.
ffmpeg -i input.mp4 -itsoffset 01 -i test_0:01.mp3 -itsoffset 20 -i test_0:20.mp3 -c:v copy -map 0:v:0 -map 1:a -map 2:a -c:a aac -b:a 192k output.mp4
Any help will be appreciated!
Your command creates two audio tracks in the MP4 file. If you have a look in your video player you can choose between two audio tracks (usually used to choose different audio languages).
Why
This is because every -map parameter creates a new stream. In your example one video with two audio tracks.
Solution
Use the audio filter amix instead. Use also the filter adelay for the delay in the same filter chain to achieve the best result.
ffmpeg -i input.mp4 -i test_0:01.mp3 -i test_0:20.mp3 -filter_complex "[1:a]adelay=1s:all=1[a1];[2:a]adelay=20s:all=1[a2];[a1][a2]amix=inputs=2[amixout]" -map 0:v:0 -map "[amixout]" -c:v copy -c:a aac -b:a 192k output.mp4
I'm trying to convert a MPEG2 Transport Stream to a MP4 stream. The video and audio are fine, but I can't seem to figure out how to tell ffmpeg to extract the eia_608 stream from the video and place it in a stream for the mp4 or mov. I've tried a straight copy as shown below.
ffmpeg -f mpegts -i tsfile3.ts -codec:v copy -fflags genpts -bsf:a aac_adtstoasc -codec:a copy -codec:s copy -f mov tsfile3a.mp4
Has anyone done this? If so, could you help with the syntax? Thanks.
Finally figured this out. Just be aware it appears to only work with mpegvideo and not h264. The syntax is as follows:
ffmpeg -i Closedcaption_rollup.ts -f lavfi -i "movie=Closedcaption_rollup.ts[out+subcc]" -map 0:0 -map 0:1 -map 1:1 -c:s mov_text test_out.mp4
This is using the ffmpeg fate test clip.
The caveats are:
Appears to only work with mpegvideo. I can't get it to work with h264
Doesn't output eia_608 type in the file, it converts it to mov_text.