Wednesday, September 19, 2018

Shuffling into YouTube's comment space -II: Quest for a video downloader capable of embedding subtitles


Now that I could get comments and captions from YouTube videos at will if they exist, I may as well play with some text analysis tools. The easiest one at hand is the wordcloud. How about sentiment analysis of comments? I've seen some examples of how to do it. Still, I need to learn more. Looking around on YouTube I found the Jayalar Academy channel and particularly its Machine Learning, Data Mining, Statistics with R topic. It looks good, and there is the video: Text Mining (part 3) - Sentiment Analysis and Wordcloud in R (single document). Now I need to download it with the subtitles intact and I thought that would be a piece-of-cake with so many freeware and open source applications around. Well, sort of!

Previously, I have used free software such as the Freemake Video Downloader and later YTD video downloader. They were fine, but I only recently noticed that they can't give a video together with the subtitles. Only recently was I aware of the YouTube videos' capability to display subtitles if they exist! So much for my YouTube experience!

Continuing with my quest for a video downloader capable of embedding subtitles, I found the 4K downloader. WikiHow stamped it as community tested and went on to instruct how to install and use it. I was impressed and immediately sent an email to my friend about this discovery.


Happily I went to their site and downloaded the (only one) installer listed there. Only after much fumbling and failing to get the embedded subtitles I found out that 4K Video Downloader needs a paid upgrade for getting that feature and other improvements. So, there's no one to blame, except myself for looking always for a free lunch.

Next, some reviews on the best YouTube downloaders sent me to try out a few online downloaders thinking vainly that they would give videos with embedded subtitles. I could get subtitle-only files; easy, free and fast, but that's not what I want. Finally I found youtube-dl.


The words, “youtube-dl is a command-line program to download videos from YouTube.com and a few more sites.” may unjustifiably frighten a senior citizen, like me, or a non-programmer. In my case, I started using PCs at the age of DOS, that predates Windows. Yet I can remember just a few commands like “dir”, “cd”, and “mkdir”. Yet, to download a video with youtube-dl is extremely simple and very fast:


The picture above shows that, in the Command Prompt window, when I run the command:
d:\yt-dl\youtube-dl.exe https://www.youtube.com/watch?v=e8QY0NDWqzk
the mp4 video file is created in my d:\yt_dl_ex directory. It is as simple as that and is much faster than with video downloaders I had used before. However, you will not get a video that includes subtitles this way. That will come later. For now, for the benefit of my fellow dummies, I will explain how I got this far.

Download, install, prepare
      1. Download youtube-dl program for Windows (youtube-dl.exe) from here.
      2. Create the D:\YT-DL folder and put youtube-dl.exe there.
      3. Create the D:\yt_dl_ex folder to place the program outputs.
Open Command Prompt
      1. Click Start and type cmd in the Search programs and files box and press Enter.
Run the program at Command Prompt
      1. At the Command Prompt type d: and press Enter.
      2. Next type cd yt_dl_ex and press Enter. Now my working directory is d:\yt_dl_ex.
      3. Now type d:\yt-dl\youtube-dl.exe https://www.youtube.com/watch?v=e8QY0NDWqzk and press enter to get the video file. You'll recall that this is the same video that I wrote about in my last post.

For my main task to get subtitles embedded in a video, I've to look for the solution in GitHub, superuser, ffmpeg-user mailing list, and other places plus a lot of silly mistakes, and trial and errors. Finally I got it done using the command:

d:\yt-dl\youtube-dl.exe --write-sub --embed-subs -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]" https://www.youtube.com/watch?v=e8QY0NDWqzk


However, you need to have the ffmpeg software installed on your computer to be able to embed the subtitles. You should read the wikiHow article on how to download and install ffmpeg on Windows here. The GitHub article on installing ffmpeg is here. If ffmpeg is correctly installed you should have no trouble getting the above results. Happy downloading YouTube videos!

However, that was not THE END! If you were as dumb as I am, you would go to the freshly downloaded video (with subtitles) and double-clicked on it and got puzzled by the outcome. You would watch your video on the Windows Media Player screen and wonder where the subtitles are hiding. You would try tweaking the Players setting, and no luck. You would again check the message from the youtube-dl run that reads:

[ffmpeg] Embedding subtitles in 'The Most Successful People Explain Why a Colleg
e Degree is USELESS-e8QY0NDWqzk.mp4'

Finally I suspected that the problem might be due to Windows Media Player not being able to play video with such embedded subtitles. So I installed the latest version of VLC player from here. And success!




No comments:

Post a Comment