Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rendering subtitles besides simply adding a subtitle stream (was: Feature request "-f bestsubtitle") #9655

Open
donizyo opened this issue Jun 1, 2016 · 24 comments

Comments

@donizyo
Copy link

@donizyo donizyo commented Jun 1, 2016

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.05.30.2. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2016.05.30.2

Before submitting an issue make sure you have:

  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your issue


If the purpose of this issue is a bug report, site support request or you are not completely sure provide the full verbose output as follows:

Add -v flag to your command line you run youtube-dl with, copy the whole output and insert it here. It should look similar to one below (replace it with your log inserted between triple ```):

$ youtube-dl -v <your command line>
[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKcj']
[debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
[debug] youtube-dl version 2016.05.30.2
[debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
[debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
[debug] Proxy map: {}
...
<end of log>

If the purpose of this issue is a site support request please provide all kinds of example URLs support for which should be included (replace following example URLs by yours):


Description of your issue, suggested solution and other information

there are already -f parameters bestvideo and bestaudio but i wonder why there is no bestsub or bestsubtitle to help burn subtitles into video files
For example:

-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]+bestsubtitle[ext=vtt]/best"

will burn both best audio and best subtitle into the mp4 file.

  • --write-auto-sub option should be automatically used if bestsubtitle is invoked but no subtitle is available
  • if bestsubtitle is invoked without bestvideo and bestaudio, download best subtitle only
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 1, 2016

How to determine the "best" one among several subtitles?

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

bestsubtitle[ext=vtt] is an arbitrary available subtitle file that is .vtt but not an automatically generated subtitle, if not available just use generated one.

How to burn subtitles into video

https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo

@yan12125 yan12125 added the request label Jun 1, 2016
@vxbinaca
Copy link
Contributor

@vxbinaca vxbinaca commented Jun 1, 2016

@yan12125 nails it with his comment.

Why is VTT better than SRT? VTT is nice for streaming sites, except for Archive.org which requires SRT.

Perhaps use --convert-subs "vtt" for uniform output?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 1, 2016

There are more formats. Besides WebVTT and SRT, TTML, SMPTE-TT, SSA are also common. For videos and audios, bitrates, filesizes and resolutions are the three primary metrics. Are there comparable quantities for subtitles? It no, hard-coding order may also be acceptable.

How to burn subtitles into video

@donizyo FYI: this is already implemented via --embed-subs.

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

but what about the feature download subtitle only?

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

suppose i've downloaded a video and an audio and they are merged into a .mp4 file but i forgot to download auto generated subtitle

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 1, 2016

  1. youtube-dl also downloads subtitles if --write-sub given. To download subtitles only but not videos, add --skip-download.
  2. --embed-subs reads from existing files if there are files with the same name as the output of --write-sub.
@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

just ran a test, youtube-dl failed to burn VTT subtitle into merged video file (:зゝ∠)

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 1, 2016

Please post the output your command. Don't forget to add -v to your commands.

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

$ ytdl --playlist-start 29 "https://www.youtube.com/playlist?list=PLjyuVPBuorqIhlqZtoIvnAVQ3x18sNev4"
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['--verbose', '--proxy', 'http://127.0.0.1:8087/', '--socket-timeout', '1200', '--yes-playlist', '-o', '%(playlist_index)s.%(ext)s', '--user-agent', 'Mozilla/5.0 (Windows NT 6.0; rv:46.0) Gecko/20100101 Firefox/46.0', '--write-auto-sub', '--sub-format', '"srt/best"', '--embed-subs', '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '--recode-video', 'mp4', '--no-post-overwrites', '-k', '--playlist-start', '29', 'https://www.youtube.com/playlist?list=PLjyuVPBuorqIhlqZtoIvnAVQ3x18sNev4']
[debug] Encodings: locale cp936, fs mbcs, out cp936, pref cp936
[debug] youtube-dl version 2016.05.30.2
[debug] Python version 3.5.1 - Windows-7-6.1.7601-SP1
[debug] exe versions: ffmpeg N-80123-gd74cc61, ffprobe N-80123-gd74cc61
[debug] Proxy map: {'http': 'http://127.0.0.1:8087/', 'https': 'http://127.0.0.1:8087/'}
[youtube:playlist] PLjyuVPBuorqIhlqZtoIvnAVQ3x18sNev4: Downloading webpage
[download] Downloading playlist: Blender Video Editing (2.7X series [Current Series])
[youtube:playlist] playlist Blender Video Editing (2.7X series [Current Series]): Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] XPndVNEA1JQ: Downloading webpage
[youtube] XPndVNEA1JQ: Downloading video info webpage
[youtube] XPndVNEA1JQ: Extracting video information
[youtube] XPndVNEA1JQ: Looking for automatic captions
[youtube] XPndVNEA1JQ: Downloading MPD manifest
WARNING: No subtitle format found matching ""srt/best"" for language en, using vtt
[info] Writing video subtitles to: 29.en.vtt
[debug] Invoking downloader on 'https://r1---sn-i3b7kn7z.googlevideo.com/videoplayback?id=5cf9dd54d100d494&itag=137&source=youtube&requiressl=yes&nh=IgpwcjA0LmhrZzAxKgkxMjcuMC4wLjE&mv=u&ms=au&mn=sn-i3b7kn7z&mm=31&pl=17&ratebypass=yes&mime=video/mp4&gir=yes&clen=53360738&lmt=1449224937977359&dur=461.033&key=dg_yt0&fexp=9413138,9416126,9416891,9422596,9428398,9430794,9431012,9433096,9433380,9433457,9433946,9434086,9435527,9435850,9435876,9435922,9437027,9437067,9437255,9437553,9438051,9438244&sver=3&mt=1464807759&upn=lO_NJqBAe4I&signature=5C4D4A9A530173AFD1312373E346142F983AE774.3A1E92942C7DF0869D2642AEB5D72231FB6541E8&ip=171.88.98.161&ipbits=0&expire=1464830061&sparams=ip,ipbits,expire,id,itag,source,requiressl,nh,mv,ms,mn,mm,pl,ratebypass,mime,gir,clen,lmt,dur'
[download] Destination: 29.f137.mp4
[download] 100% of 50.89MiB in 00:42
[debug] Invoking downloader on 'https://r1---sn-i3b7kn7z.googlevideo.com/videoplayback?id=5cf9dd54d100d494&itag=140&source=youtube&requiressl=yes&nh=IgpwcjA0LmhrZzAxKgkxMjcuMC4wLjE&mv=u&ms=au&mn=sn-i3b7kn7z&mm=31&pl=17&ratebypass=yes&mime=audio/mp4&gir=yes&clen=7324094&lmt=1449224655848039&dur=461.101&key=dg_yt0&fexp=9413138,9416126,9416891,9422596,9428398,9430794,9431012,9433096,9433380,9433457,9433946,9434086,9435527,9435850,9435876,9435922,9437027,9437067,9437255,9437553,9438051,9438244&sver=3&mt=1464807759&upn=lO_NJqBAe4I&signature=9A38A0E15065F1936C3EB430BEAC74C55F12E4C7.2C91A12B3BFEC485AFDE60CB10DE8188B85FA947&ip=171.88.98.161&ipbits=0&expire=1464830061&sparams=ip,ipbits,expire,id,itag,source,requiressl,nh,mv,ms,mn,mm,pl,ratebypass,mime,gir,clen,lmt,dur'
[download] Destination: 29.f140.m4a
[download] 100% of 6.98MiB in 00:14
[ffmpeg] Merging formats into "29.mp4"
[debug] ffmpeg command line: ffmpeg -y -i file:29.f137.mp4 -i file:29.f140.m4a -c copy -map 0:v:0 -map 1:a:0 file:29.temp.mp4
[ffmpeg] Not converting video file 29.mp4 - already is in target format mp4
[ffmpeg] Embedding subtitles in '29.mp4'
[debug] ffmpeg command line: ffmpeg -y -i file:29.mp4 -i file:29.en.vtt -map 0 -c copy -map -0:s -c:s mov_text -map 1:0 -metadata:s:s:0 language=eng file:29.temp.mp4
[download] Finished downloading playlist: Blender Video Editing (2.7X series [Current Series])
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 1, 2016

According to log vtt is embedded just fine. Post the output of ffmpeg -i 29.mp4.

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

$ ffmpeg -i 29.mp4
ffmpeg version N-80123-gd74cc61 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.101 / 57. 37.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '29.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.37.101
  Duration: 00:07:44.98, start: 0.000000, bitrate: 1048 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 922 kb/s, 30 fps, 30 tbr, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
At least one output file must be specified
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 1, 2016

Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 1, 2016

for now, i'm using my own burning function... (:зゝ∠)

function burn_subtitle
{
    # param1: video extension
    ext_vid=$1
    # param2: subtitle extension
    ext_sub=$2
    for file in *.$ext_vid; do
        idx=`expr index $file "."`;
        ((idx-=1));
        name=${file:0:$idx};
        file_sub=$name"."$ext_sub;
        file_out=$name"_out.mp4";
        echo "[BURN] Merge $file and $file_sub into $file_out ..."
        if [ ! -f $file_sub ]; then
            echo "[BURN] File $file_sub not found!"
            continue;
        fi
        ffmpeg -loglevel 0 -i $file -vf subtitles=$file_sub $file_out
    done
}
$ burn_subtitle "mp4" "vtt"
[BURN] Merge 29.mp4 and 29.vtt into 29_out.mp4 ...

$ ffmpeg -i 29_out.mp4
ffmpeg version N-80123-gd74cc61 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.101 / 57. 37.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '29_out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.37.101
  Duration: 00:07:41.13, start: 0.000000, bitrate: 849 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 708 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 132 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
At least one output file must be specified

and it works fine

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 2, 2016

Please check against the file generated by youtube-dl but not your script.

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 2, 2016

@yan12125
problematic output is generated by youtube-dl, my script is fine

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 2, 2016

Could you point out the "problematic output"? Seems both youtube-dl and ffmpeg outputs are fine.

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 2, 2016

@yan12125
the part quoted by @dstftw is buggy
FULL

$ ffmpeg -i 29.mp4
ffmpeg version N-80123-gd74cc61 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.101 / 57. 37.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '29.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.37.101
  Duration: 00:07:44.98, start: 0.000000, bitrate: 1048 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 922 kb/s, 30 fps, 30 tbr, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : SubtitleHandler
At least one output file must be specified

PART

Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 2, 2016

The subtitle stream is for storing subtitles, and it can be parsed and played correctly with latest mpv. For example:
screenshot_2016-06-02_12-33-59
Which player are you using?

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 2, 2016

VLC and windows media player won't work

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 2, 2016

@yan12125
did you delete VTT file in directory before you watch the video?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 2, 2016

did you delete VTT file in directory before you watch the video?

Yes.

VLC and windows media player won't work

Confirmed. VLC 2.2.3 can't recognize the embedded WebVTT subtitle. VLC nightly needed.

Windows Media Player...Is it really a functional media player? :D

To sum up: the current approach adds a subtitle stream. youtube-dl need some way to render the subtitle directly on the video. Is it what you want?

@donizyo
Copy link
Author

@donizyo donizyo commented Jun 2, 2016

yep, i think i'm gonna render it with -vf subtitles=29.vtt instead of -i 29.vtt -c:v copy

@yan12125 yan12125 changed the title Feature request "-f bestsubtitle" Allow rendering subtitles besides simply adding a subtitle stream (was: Feature request "-f bestsubtitle") Jun 2, 2016
@yan12125 yan12125 added the subtitles label Jun 2, 2016
@dstftw dstftw mentioned this issue Jun 8, 2016
5 of 8 tasks complete
@kitokirisaki
Copy link

@kitokirisaki kitokirisaki commented Jun 17, 2016

When will be implemented (Hardsubs)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.