How to burn / hardcode subtitle to the downloaded youtube video with youtube-dl - youtube-dl

This command downloads the video and embed the auto-generated youtube subtitle to the file
youtube-dl.exe -ci -f "bestvideo[ext=mp4]"+"bestaudio[ext=m4a]" --write-auto-sub --embed-subs --merge-output-format mp4 https://www.youtube.com/watch?v=k4rCdHsdiss
However the subtitle is only embedded. I want it to be burned/hardcoded so that it can be played on non-embed supporting platforms such as treadmill
I am using windows 10

youtube-dl cannot burn the subtitles by itself. You need to use postprocessors like FFmpeg or avconv for it. youtube-dl use them internally for some tasks. As you successfully used bestvideo+bestaudio argument, you already have installed one of these in your system. avconv is a fork of FFmpeg, so they accept mostly the same arguments. I'll show the FFmpeg case here.
youtube-dl has a feature to add arguments to the postprocessors but I can't see how to use it to solve this task.
Other possibility is using --exec flag. Regretfully, I have not a Windows machine now so I wrote only Linux variant.
youtube-dl -f "[height=360][ext=mp4]+bestaudio[ext=m4a]" --write-sub --write-autosub --embed-subs --exec "mkdir temp && ffmpeg -i {} -vf subtitles={}:force_style='FontName=Arial' -acodec copy temp/{} && mv -f temp/{} {} && rm -r temp" --restrict-filenames AO4In7d6X-c
This is a one-line command but it has several flaws:
You must use --restrict-filenames to make it work. No more nice filenames.
I see no way to have more than one option for subtitle style, i. e. font name, font color and font size.
Very cumbersome.
So my best guess is using FFmpeg manually or with a batch script after downloading the video with youtube-dl. Not tested on Windows but it should work well.
ffmpeg.exe -i "input.mp4" -vf subtitles="filename='input.mp4':force_style='FontSize=20,FontName=Arial'" -c:v libx264 -x264-params crf=22 -preset fast -profile:v high "output.mp4"
input.mp4 must be a file with embedded subtitles.
FFmpeg must be compiled with the support of libass. Type ffmpeg.exe without arguments and look for --enable-libass. libx264 is recommended too.
To tune the speed of encoding you may use a different preset. Allowed values are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. Faster presets mean bigger file size.
To tune quality use crf parameter. The smaller the number the better quality but also the bigger file size. Numbers from 16 to 30 are optimal.
If the file fails to play on some old players, you may try to use the profile baseline and lower the level.

Related

FreeType Glyph Metrics Caching of multiple Font sizes

Situation:
I have a project that renders product information onto a given template (custom XML format), then renders and converts it in a custom binary LCD format (steps simplified)
Our customers now want auto-fitting text container. (customer gives a box of specific size and all kinds of strings have to get auto-resized to fit into that container
For that I have to calculate the width of the string (freetype: each char/glyph) for multiple font-sizes (e.g. 100pt doesnt fit, 99pt doesnt fit, 98pt doesnt..., ..., 65pt fits!)
Problem:
The Problem is that freetype takes a lot of time (~20-30 ms) for each auto-fit element and I have only ~100ms for my whole application to use. (so when customer adds 5 more autofit elements it's already guaranteed to exceed ~100 ms)
Attempts:
A selfmade font-cache-generator which takes a font-file and calculates the widths of each unicode-character for font-sizes from 1pt to 100pt. Then it generates C source code out of the data like this:
//
#define COUNT_SIZES 100 // Font-Size 1-100
#define COUNT_CHARS 65536 // Full Unicode Table
int char_sizes[COUNT_SIZES][COUNT_CHARS] =
{
{1,1,2,2,3,1,1,2,2,3,1,2,2,1,2,2,3,1,2,.......// 65536
{2,2,3,3,4,2,1,3,3,4,2,3,3,2,3,3,4,2,3,.......// 65536
{2,3,4,3,5,2,2,4,4,5,2,4,4,2,4,3,5,3,3,.......// 65536
// ...
// 100 font sizes
};
That compiled in a dynamic lib (.so) is 25 MB in size and takes ~50ms to "dlload" and ~10ms to "dlsym" (WAAAAAAY too much!)
The same way but only ASCII table (so only 128 of 65536) compiles into a 58 KB .so file and takes ~500µs for "dlload" and ~100µs for "dlsym" (very nice!)
My next attempt would be to integrate the font-cache-generator into my project and cache only the glyphs I need for the specific customer (customer in europe needs ~500 glyphs, one in asia (e.g. traditional chinese) needs ~2500 (only examples, not exactly sure, maybe even more needed)
But before I take on that hard-work journey (:() I wanted to ask you if you know a better way of doing it? A library/project that does just that?
I cannot believe that it's not possible, how should a browser show lorem ipsum without loading seconds otherwise? :D
Any idea on how to solve this performance issue?
Any informative link on data caching with extremly fast access to cache (somewhat <1ms)?
System Info:
Unix (Ubuntu 16.04) 64bit
x86 AND arm architectures exist!
I found one possible way using these libraries:
ICU (for unicode)
Freetype (for the Glyphs)
Harfbuzz (for layout)
Github Project:
Harfbuzz-ICU-Freetype
Loose build instructions:
Search options in CMakeLists.txt option(WITH_XX "DESCRIPT." ON/OFF)
Enable CMake options with -D: cmake -DWITH_ZLIB=ON -DWITH_Harfbuzz=ON ..
mkdir build && cd build && cmake [option [option [...]]] ..
make -j $count_of_cpu_cores && sudo make install
Google for some Harfbuzz Layout tutorials / guides

Omxplayer cuts off roughly the last second of sound

I am using Omxplayer to play a sound file stored as .MP3
The issue I am facing is that on sound files with duration > 1 second, but < 10 appear to have the end (roughly a second) of the file cut off abruptly as if the track had finished.
I am unsure what could be causing this issue as Omxplayer throws no errors and just cuts out to its usual "Have a nice day"
This is on Raspbian on Pi.
Workaround I ended up using was to convert my .mp3 files to .wav, and that stopped them from being cut off. The conversion was easy enough, and it might help down the line since .wav seems to be more acceptable for a variety of tools, e.g. aplay.
I looped through each of them and used the tool lame to convert
sudo apt-get install lame
lame --decode /path/to/file.mp3 /new/path/to/file.wav
Since I happened to be having this problem in Node, I'll share that full solution to convert all .mp3 files in a directory to .wav in a loop. This assumes you have a folder full of only mp3 files, and doesn't check to enforce that:
const fs = require("fs");
const { exec } = require("child_process");
const files = fs.readdirSync("./audio_mp3/");
files.forEach((file) => {
let newFile = file.replace('.mp3', '.wav')
exec(`lame --decode ./audio_mp3/${file} ./audio_wav/${newFile}`);
console.log(`Created ${newFile} in folder ./audio_wav/`);
})

performance.exe in opencv autoclose when finish

i'm new to opencv,i have done the haar-training and get a decent detection. However, when i want to check my hit rate by using performance.exe, it run until finish and auto-close and i cannot check the hit rate, how to solve this? thanks
Assuming, you are running performance on command prompt; Go to the command line and run:
C:\Program Files\OpenCV\bin> performance -data TrainingSample.xml -info TestingSample\testsample.txt -sf 1.2 -w 15 -h 20 > TestResult.log
You need to place TestingSample.txt in the folder TestingImages, if you do not put the TestingSample.txt into TestingImage then performance program will execute but will not save and show any result. > TestResult.log is used to direct the result of execution to log file rather than screen, you can remove it.
Adjust OpenCV path. Please post in details if you see any more problem.
Happy Coding :)

CImg Error : 'gm.exe' is not recognized as an internal or external command,

I am new to c++ programming , today i was trying to save an image using CImg .
CImg is C++ Template Image Processing Library .
The basic code i wrote is(Please forgive any syntax erros , as copied part of my codes) :
#include "CImg.h"// Include CImg library header.
#include <iostream>
using namespace cimg_library;
using namespace std;
const int screen_size = 800;
//-------------------------------------------------------------------------------
// Main procedure
//-------------------------------------------------------------------------------
int main()
{
CImg<unsigned char> img(screen_size,screen_size,1,3,20);
CImgDisplay disp(img, "CImg Tutorial");
//Some drawing using img.draw_circle( 10, 10, 60, RED);
img.save("result.jpg"); // save the image
return 0;
}
But I cannot run my program as it says :
Invalid Parameter - 100%
'gm.exe' is not recognized as an internal or external command,
operable program or batch file.
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
[CImg] *** CImgIOException *** [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.
terminate called after throwing an instance of 'cimg_library::CImgIOException'
what(): [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.
Though i can see the image , I cannot save it.
After googling a bit i found people saying to install ImageMagick , i have installed it but no help .
Some of the Forum says to compile against libjpeg, libpng, libmagick++. But i don't know how to compile against those libraries.
I am using Eclipse CDT plugin to write C++ project .
Please help me .
I had the same error, and installing of GraphicsMagick (not ImageMagick) helped me.
I've downloaded and installed GraphicsMagick-1.3.26-Q8-win64-dll.exe from ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/windows/. You may choose another one, if you need:
Note that the QuantumDepth=8 version (Q8) which provides industry
standard 24/32 bit pixels consumes half the memory and about 30% less
CPU than the QuantumDepth=16 version (Q16) which provides 48/64 bit
pixels for high-resolution color. A Q8 version is fine for processing
typical photos intended for viewing on a computer screen. If you are
dealing with film, scientific, or medical images, use ICC color
profiles, or deal with images that have limited contrast, then the Q16
version is recommended.
Important: during installation, don't remove checkbox "Update executable search path", which updates environment variable %PATH%, making gm.exe available from any place.
In my case, it was also required to install Ghostscript - which is highly recommended to install by GraphicsMagick. There is a link to x64 Ghostscript: https://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/9.09/gs909w64.exe/download (I've put it here, because links from the GraphicMagick websites leads you to 32-bit only).
After that, it worked fine for me.
For some image formats (as .jpg, .png, .tif and basically all formats that require data compression), CImg will try to use an external tool to save them (such as convert from ImageMagick or gm from GraphicsMagick).
If you don't have any installed, then you won't be able to save .jpg files without having to link your code with the libjpeg library, to get a native support for JPEG read/write (then, you'll need to #define cimg_use_jpeg before #include "CImg.h", to tell the library you want to use the libjpeg features).
If you want to keep things simpler, I'd recommend to save your image using another (non-compressed) image format, as .bmp or .ppm.
These formats are handled natively by CImg and do not require to link with external libraries.
I know this question is old, but I kept getting the same error on one project and not on another and this is the only thing on Google.
To get rid of it, you must do 2 things:
Install dynamic ImageMagick libraries for your appropriate OS and architecture(32/64). Link
I was using VisualStudio, and the character set must be set to "Unicode". The error would appear again when I reverted back to Multi-Byte character set. I guess this has something to do with the way CImg handles strings and miscompares them.

Identify a mounted volume as a CD/DVD on osx

When you mount anything on osx it shows up under /Volumes/mountname
Is there any way, using the commandline or C/C++ to identify the volume as a CD/DVD rom?
My current best idea goes something like this.
df | grep mountname
to get the /dev/diskNsM path
and then
drutil | grep /dev/diskN
to see if the path mounted device is the burner.
This works, but i'm concerned about the case where the CD/DVD is not a burner. Will it still show up in the output of drutil? Do macs even come with a non-burner CD/DVD drive?
Also i would prefer using C,C++ or objective C to do this.
I already use
const char *tmp = '/Volumes/mysterydrive';
statfs(tmp, &m);
if(m.f_flags & MNT_RDONLY)
{
read_only = true;
}
to determine if the volume is readonly,
but i cannot see if this or any related call can distinguish between a CD/DVD and a readonly mounted volume.
It would only need to work for OSX 10.5 and newer.
Any ideas?
EDIT:
Using
diskutil info /Volumes/mysterydrive
I got the following output if its a CD/DVD
Optical Drive Type: CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, DVD-RW, DVD+R, DVD+R DL, DVD+RW
Optical Media Type: DVD-R
Optical Media Erasable: No
And that's all i need!
I'll look into using IOKit to do it programmatically later, but this seems to be the quickest way to get it done.
You get the most detailed information from
diskutil info /Volume/foo
In particular see Optical Drive and Optical Media entries which you only get for CD/DVDs so it is quite reliable.
Unfortunately the frameworks that diskutil uses to get all that information are private, so it will be hard to replicate it in C code.
I didn't dig deeper into other options, but since you can get the disk name from statfs it may be in theory possible to use IOKit to check out the device and you'll see IOCDMedia or IODVDMedia class if it is a CD/DVD drive (i.e. if you look for IO*Media class the BSD Name property has the disk name like disk6)
Apple Developer Central has a sample code project called CDROMSample that shows using IOKit routines to access CD-ROM properties. This might give you a start into handling DVDs, as well.