[Eiffel-Loop] Utility to download youtube videos in UHD (4K) and convert to mp4

241 views
Skip to first unread message

Finnian Reilly

unread,
Feb 11, 2018, 1:27:40 PM2/11/18
to Eiffel Users
There are a large number of ultra-high definition (4K) videos on youtube, but it's possible most people don't have enough bandwidth to be able to watch them. Today I added a new sub-option -youtube_dl to the multi-purpose utility el_toolkit that allows you to download 4K UHD to your hard disk and convert it to MP4 format. This utility depends on two other utilities being installed: youtube-dl and ffmpeg. The code for this utility is in two classes: YOUTUBE_HD_DOWNLOAD_APP and YOUTUBE_HD_DOWNLOAD_COMMAND.

The program which does the actual work of downloading the videos is called youtube-dl. This utility is useful but has a major problem when it comes to downloading 4K youtube videos. The problem is that 4K youtube videos do not include the sound channel, which you need to download separately and then merge them into a single file.

If you select the "-best" option with youtube-dl you imagine it would select the 4K version (if one exists) but that is not what happens. The "-best" option only applies to videos that have a combined video and sound channel. As far as I can tell, youtube-dl does not provide a remedy for this.


The other problem is that 4K videos from youtube are usually in webm format which is not as portable as mp4. For example I can't play webm videos on my Playstation console (which has a monitor capable of displaying 4K videos) The utility I wrote downloads the 4K video and audio track separately and then merges them to create a MP4.


Warning

The ffmpeg conversion process from mp4 to webm is very processor intensive. Even with an 8 core CPU it can take 30 mins or so to convert a 5 minute video.


Download


A build for Ubuntu 14.04.5 (Trusty Tahr) is available to download here.





Finnian Reilly

unread,
Feb 11, 2018, 2:11:03 PM2/11/18
to Eiffel Users
Canonical Spacing
As a point of interest, this utility make use of some new routines recently added to class EL_ZSTRING, namely: is_canonically_spaced, to_canonically_spaced and as_canonically_spaced.

Originally I added them for use with the Amazon Instant Access API. See class AIA_CANONICAL_REQUEST, but once again they are proving useful.

Hubert Cater

unread,
Feb 12, 2018, 9:04:43 AM2/12/18
to Eiffel Users
Great stuff Finnian :)


Virus-free. www.avast.com

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.

Finnian Reilly

unread,
Feb 13, 2018, 5:59:40 AM2/13/18
to Eiffel Users

Improvements to 4K youtube video download Linux utility

I have made the following improvements to this utility
  • Found a solution to the problem of ffmpeg progress output not being visible. The ffmpeg command sends console output via stderr so when it is launched from Eiffel you can't see anything. Adding 2>&1 doesn't help matters. So in the end the solution was to fork the ffmepg process and read the conversion progress messages via a Unix socket and render a progress bar in Eiffel. (See ffmpeg -progress option)
  • Polished and better documented the code. The code was improved with the addition of class YOUTUBE_STREAM_INFO.

Notes and Tips

  • Sometimes a video is available at either 60 fps or 30 fps. Generally `youtube-dl -F' will list the 30 fps stream first, so this is the one that is selected. This is prefered as a 60 fps video may take a long time to download on slower connections, and also the conversion to mp4 from webm format is pretty CPU intensive and will take twice as long.
  • If you do not use the `-url' option, you will be prompted to drag and drop a url from a browser youtube search listing.
  • You will be prompted to add a title which will be added as meta data to the download. The filename is this title lower-kebab-cased. Thought about using the original youtube video title, but most are too long to be practical. Better to add your own short title.
  • If you plan to use this utility often, you can set up a desktop launcher configured like this (icon attached). A pity the %u placeholder doesn't seem to work (at least on my system). I was hoping to be able to drag a drop a URL on to the launcher. Placeholder %f works with files.
[Desktop Entry]
Comment=
Terminal=false
Name=Youtube HD
Exec=gnome-terminal --command="el_toolkit -youtube_dl -ask_user_to_quit" --geometry 140x50+100+100 --title="Youtube Download"
Type=Application
Icon=/home/<user name>/Graphics/icons/youtube_v2-512.png

Download Latest

Build for Ubuntu 14.04.5 (Trusty Tahr)

http://www.eiffel-loop.com/download/el_toolkit-1.2.4


Roll your own build

  1. Check out Eiffel-Loop from http://github.com/finnianr/Eiffel-Loop/
  2. Run the setup.sh script in the library root to set up the scons build system etc.
  3. Do cd Eiffel-Loop/tool/toolkit and run . build_and_install.sh (installs to /usr/local/bin)


Colin Adams

unread,
Feb 13, 2018, 6:04:06 AM2/13/18
to eiffel...@googlegroups.com
Why not just use the process libraray to handle the output of ffmpeg with an agent?

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.

Finnian Reilly

unread,
Feb 13, 2018, 6:23:03 AM2/13/18
to Eiffel Users

Why not just use the process libraray to handle the output of ffmpeg with an agent?
A good question Colin, and indeed I was looking into using the process library, but I didn't for the following reasons:
  1. I couldn't find any examples in EiffelStudio_16.05 and it is not at all obvious how to use it by inspecting the classes provided.
  2. I did remember once seeing a tutorial on how to use them but I had trouble to find it again. Perhaps someone can post the link here.
  3. Once I had worked out the appropriate ffmpeg command options for -progress, the Eiffel code was pretty simple. I already had a class for making a progress bar. See routine do_conversion in class YOUTUBE_HD_DOWNLOAD_COMMAND.
  4. I recently fell in love with Unix sockets and wanted more practice at using them :-)
  5. My OS-command library does one thing very well, and that is automatically escaping reserved characters for path names. This has some advantages over merely enclosing paths in quotes. My template substitution class doesn't have this facility.

Woland's Cat

unread,
Feb 13, 2018, 9:22:15 AM2/13/18
to eiffel...@googlegroups.com
On 13/02/2018 08:03, Colin Adams wrote:
Why not just use the process libraray to handle the output of ffmpeg with an agent?

yes, that works fine - I did it to display real time feedback from git whenever my application is running a Git operation.

- thomas

--
Thomas Beale
Principal, Ars Semantica
Consultant, ABD Team, Intermountain Healthcare
Management Board, Specifications Program Lead, openEHR Foundation
Chartered IT Professional Fellow, BCS, British Computer Society
Health IT blog | Culture blog

Jocelyn Fiat

unread,
Feb 13, 2018, 12:01:10 PM2/13/18
to Eiffel Users
But it should be updated to include agent redirection.

-- Jocelyn

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users+unsubscribe@googlegroups.com.



--
Jocelyn
------------------------------------------------------------------------
Eiffel Software
https://www.eiffel.com
Customer support: https://support.eiffel.com
User group: https://groups.google.com/forum/#!forum/eiffel-users
------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages