% VCP-Embedding-Subtitles.tex
% Hussein Esmail
% Created 2021 04 24
% Updated 2021 04 24
% Description: [DESCRIPTION]

% This file can be found at https://husseinesmail.com/guides/all/

\documentclass{article}
\title{Embedding Subtitles Into a Video using Ffmpeg}
\author{Hussein Esmail}
\date{April 27, 2021} % Current date rather than creation date

\usepackage{hyperref}   % This block contains information used for PDF metadata
\usepackage{listings}   % Used for blocks of code

\hypersetup{
    colorlinks=false, 
    pdfborder={0 0 0},
    pdftitle={Embedding Subtitles Into a Video using Ffmpeg}, 
    pdfauthor={Hussein Esmail}, 
    pdfsubject={VCP Video Editing},
    pdfkeywords={Vanier College Productions, Video Editing, VCP, ffmpeg}
}

\lstset{
  basicstyle=\ttfamily,
  frame=single,
  breaklines=true
}

\newcommand{\comment}[1]{} % \comment{Multiline comments can go here.}

\begin{document} % Official beginning of the document. 
\maketitle
\begin{center}
    Edited: \today
\end{center}
\newpage
\tableofcontents
\newpage

\section{Introduction}
This PDF is meant to be an instruction to those who want to embed subtitles into a video file. The original purpose of this was to hard-code subtitles into a video to be played on Streamyard.

At the time of writing this document, all URLs are correct. Should you have any issues, please \underline{\href{mailto:HusseinEsmailContact@gmail.com}{feel free to send me an email}}. You can access this PDF at \underline{\href{https://husseinesmail.xyz/guides/vcp/VCP-Embedding-Subtitles.pdf}{https://husseinesmail.xyz/guides/vcp/VCP-Embedding-Subtitles.pdf}}.

\section{Installing Ffmpeg}
Installing ffmpeg may be different per operating system, so here are some YouTube videos that can explain better than me how to do so:

\begin{tabular}{l|l}
    Windows &   \href{https://youtu.be/r1AtmY-RMyQ}{\underline{YouTube Video}} \\
    macOS &     \href{https://youtu.be/sQsy66vI0xw}{\underline{YouTube Video}}
\end{tabular}
\section{Difference Between ``Hard-coding'' and ``Soft-coding''}
\begin{itemize}
    \item \textbf{Hard-coding}: This is if you want to have text always in the video and not be able to remove it or turn it off. The limitation with this is that you cannot extract the original video from this, and you cannot change the font size/colour after making this new file with the hard-coded subtitles. This will always be the same regardless of how you are playing the video.
    \item \textbf{Soft-coding}: This is if you want to have text that can be turned on and off depending on preference, and while watching the video you have embedded, (and depending on your video player) you can change the font size, colour, and font of the subtitles because they are overlay-ed in a way. This is similar to playing a YouTube video with Closed Captions turned on.
\end{itemize}

\section{Adding Hard-coded Subtitles}

\begin{lstlisting}
    ffmpeg -i "input.mp4" -vf subtitles="subtitle.srt" "output.mp4"
\end{lstlisting}

This one-line command takes the input video as-is and essentially places the subtitle's text above the video and makes that the new video `stream', which also means that you cannot retrieve the input video from the output video (because the text overwrites the colours that were underneath it).

Info about the command:
\begin{itemize}
    \item \textbf{``input.mp4''}: The filename of the video you want to convert (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks.  
    \item \textbf{``subtitle.srt''}: The filename of the subtitle you want to convert (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks. This works with .vtt, .srt, etc., so you don't have to worry about which file type to use.
    \item \textbf{``output.mp4''}: The filename if the video it's going to generate (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks. 
    \item You will also need to make sure your Terminal/Command Prompt is in the same directory as the file you want to convert.
\end{itemize}

\section{Adding Soft-coded Subtitles}
Here is the main command for adding soft subtitles:

\begin{lstlisting}
    ffmpeg -i "input.mp4" -i "subtitle.srt" -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng  -disposition:s:0 default "output.mp4"
\end{lstlisting}

This one-line command copies the video and audio from the source video, and copies the subtitles as the set language (in this case, English) to the output video. 

Info about the command:
\begin{itemize}
    \item \textbf{``input.mp4''}: The filename of the video you want to convert (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks. 
    \item \textbf{``subtitle.srt''}: The filename of the subtitle you want to convert (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks. This works with .vtt, .srt, etc., so you don't have to worry about which file type to use.
    \item \textbf{``output.mp4''}: The filename if the video it's going to generate (with the extension). If there are spaces in the filename, make sure the entire filename is surrounded by quotation marks. 
    \item You will also need to make sure your Terminal/Command Prompt is in the same directory as the file you want to convert.
\end{itemize}

\end{document} % Official end of the document. 
