Convert TS with closed captions into MKV/MP4 with sub title - ffmpeg

I am trying to convert a TS file ( with US closed captions ) into MKV ( or MP4 ). Currently I am doing using a three step approach.
Step-1 : Extract the subtitle in srt format.
ffmpeg -f lavfi -i "movie=test.ts[out0+subcc]" -map s output.srt
Step-2 : Transcode the TS into MKV
ffmpeg i test.ts -vcodec libx264 -acodec copy out.mkv
Step-3 : Add subtitle back to out.mkv
ffmpeg -i out.mkv -i output.srt -acodec copy -vcodec copy -scodec copy final.mkv.
I believe all these three steps can be combined in a single ffmeg command. Is there any way to do this?.

You can try
ffmpeg -i test.ts -f lavfi -i "movie=test.ts[out0+subcc]" -map 0 -map 1:s -c:a copy -c:s srt final.mkv
Hopefully, the timestamps for the subtitles will be in sync :)

Related

How to use -filter_complex and -vf in same command in FFMPEG

I edit the video with the command
ffmpeg -i video.mp4 -y -vf eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t -c:a copy output.mp4
then the resulting video
ffmpeg -i output.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I tried to combine all this together so that I didn't have to spend time processing the video twice, but I couldn't do it because you can't use the -vf and -filter_complex commands together. How can this problem be solved?
First apply the video specific filters before using the result as overlay input.
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v]eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t[vid];[vid][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4

How to I convert all audio tracks to eac3 and keep all subtitles?

I'm not familiar with ffmpeg, but came across this script that takes in the file and creates an output with eac3 audio.
#!/bin/sh
echo "Dolby Digital Plus Muxer"
echo "Developed by #kdcloudy, not affiliated with Dolby Laboratories"
echo "Enter the file name to be converted: "
read filepath
if [! -d $filepath]
then
exit $err
fi
ffmpeg -i $filepath -vn ddp.eac3
ffmpeg -i $filepath -i ddp.eac3 -vcodec copy -c:a eac3 -map 0:s -map 0:v:0 -map 1:a:0 output.mp4
rm ddp.eac3
I'd like to know what to modify in this code to ensure all the subtitles are copied from the original file and all the available audio tracks are converted to eac3 and added to the output.mp4 file.
For the subtitles copying I tried -map but couldn't get it to work. Thanks for the help!
You only need one ffmpeg command:
ffmpeg -i input.mkv -map 0 -c:v copy -c:a eac3 -c:s copy output.mkv
-map 0 Selects all streams. Otherwise only one stream per stream type will be selected. See FFmpeg Wiki: Map for more into on -map.
-c:v copy Stream copy all video.
-c:a eac3 Encodes all audio to E-AC-3.
-c:s copy Stream copy all subtitles.
For compatibility this assumes that the input and output are both Matroska (.mkv).
That script is not great. Here's a cleaner, simpler version (not that I think a script is necessary for this):
#!/bin/bash
# Usage: ./eac3 input.mkv output.mkv
ffmpeg -i "$1" -map 0 -c:v copy -c:a eac3 -c:s copy "$2"
If you want to convert a whole directory see How do you convert an entire directory with ffmpeg?

How to add a Subtitle as default to a video already containing a subtitle stream using ffmpeg? [duplicate]

By adding an .ass subtitles track to an mkv video with ffmpeg, it isn't set as default track, so on playback you have to manually turn on subtitles. Is it possible to set the default flag for the subtitles track?
ffmpeg command used:
ffmpeg -i video.mp4 -i subtitles.ass -c:v libx264 -preset veryslow \
-pix_fmt yuv420p10le -c:a copy -c:s copy output.mkv
Note that I want to keep .ass subtitle format, not convert the subtitles to mov_text like suggested in this similar question:
How to set default streams with ffmpeg
There is the possibility to set the default flag afterwards with mkvpropedit like this:
mkvpropedit output.mkv --edit track:s1 --set flag-default=1
But is it possible to do this directly with ffmpeg?
I think as per this patch this is now possible. At least for me it works with:
ffmpeg -i in.mp4 -i in.srt -c copy -disposition:s:0 default out.mkv
Note s in -disposition:s:0 in this case stands for subtitle and not stream. To select the second steam by index use -disposition:1.
You can use 'forced' instead of default to force vlc to play it
ffmpeg -f mp4 -i outfile.mp4 -f srt -i VTS_07_0.EnglishV2.srt -c:v copy -c:a copy -metadata:s:a:0 language=Japanese -c:s mov_text -metadata:s:s:0 language=English -disposition:s:s:0 forced mix.mp4

FFMPEG remove codec x264 to final films

I am processing my movie in ffmpeg (file merging, stabilization). The resulting metadata file gets an x264 codec. What prevents it from being reprocessed?
I decided to remove the codec using the Internet.
script:
ffmpeg -i input.mp4 -c copy -map 0 -metadata creation_time="2017-09-18 13:30:04" output.mp4
ffmpeg -i output.mp4 -vcodec copy -acodec copy -vbsf h264_changesps=removesei -map_metadata -1 out.mp4
pause
Unfortunately it does not work:
Unknown bitstream filter h264_changesps
What am I doing wrong?

ffmpeg error when I make TS file

I use ffmpeg to make video from audio/image to mp4.
I want merge/concatenate two mp4 video.
I have this to make mp4 video:
ffmpeg -i "background.png" -i "audio.mp3" -y -r 30 -b 2500k -acodec ac3 -ab 384k -vcodec mpeg4 "result.mp4"
This, it works!
To concatenate two mp4 video, I must pass by ts files.
ffmpeg -i "result.mp4" -codec copy -bsf:v hevc_mp4toannexb intermediate1.ts
But, I have this error:

Resources