13

I am using FFMPEG to hard code subs into a video. Having read many posts on the best approach, and whether to use mkv or mp4, but am still none the wiser. The code below uses an mp4 file. The subtitles appear to be processed, judging by the output, but the size 0kb seems to show that nothing is actually rendered, and the output file has audio and video, but no subtitles.

Metadata in VLC shows that a subtitle file is present - but empty.

Here is an example of my SRT file (not putting an empty line in 1 gives an input error msg):

1
00:00:00,000 --> 00:00:00,001

2
00:00:00,001 –-> 00:00:04,761
He drives to school every morning

3
00:00:04,761 –-> 00:00:13,061
Cause love comes slow and it goes so fast

My command line code is:

`ffmpeg -i #{inputfile} -i #{srt_file}  -filter_complex "[0:v][1:s]overlay" #{outputfile} -y`

I have also tried:

`ffmpeg -i #{inputfile} -i #{srt_file}  -c:v libx264 -preset ultrafast \
-c:s mov_text -map 0 -map 1 #{outputfile}`

And the response:

ffmpeg version 2.5.4 Copyright (c) 2000-2015 the FFmpeg developers
built on Feb 25 2015 15:52:19 with Apple LLVM version 6.0 (clang-600.0.54) 
(based on LLVM3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.4 --enable-shared --enable-pthreads
--enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --
host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc 
--enable-libxvid --enable-libass --enable-vda
libavutil      54. 15.100 / 54. 15.100
libavcodec     56. 13.100 / 56. 13.100
libavformat    56. 15.102 / 56. 15.102
libavdevice    56.  3.100 / 56.  3.100
libavfilter     5.  2.103 /  5.  2.103
libavresample   2.  1.  0 /  2.  1.  0
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 
'/Users/JW/Dropbox/T10/SBRI/_code/videos_final/3rd person present tense (303).mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.15.102
Duration: 00:00:43.17, start: 0.036281, bitrate: 862 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x406 [SAR 406:405 DAR 
16:9], 732 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
  handler_name    : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s    
(default)
Metadata:
  handler_name    : SoundHandler
Input #1, srt, from '/Users/JW/Dropbox/T10/SBRI/_code/subs/3rd person present tense (303)/srt_file.srt':
Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: subrip
[srt @ 0x7fd082005c00] sub2video: using 720x576 canvas
[libx264 @ 0x7fd082801200] using SAR=406/405
[libx264 @ 0x7fd082801200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fd082801200] profile High, level 3.0
[libx264 @ 0x7fd082801200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft     
2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 
analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 
trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 
lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 
constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 
weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf 
mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to '/Users/JW/Dropbox/T10/SBRI/_code/videos_final/3rd person present tense 
(303)_subs.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.15.102
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 720x406 [SAR 406:405 
DAR 16:9], q=-1--1, 23.98 fps, 24k tbn, 23.98 tbc (default)
Metadata:
  encoder         : Lavc56.13.100 libx264
Stream #0:1(und): Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 
s16, 128 kb/s (default)
Metadata:
  handler_name    : SoundHandler
  encoder         : Lavc56.13.100 libvo_aacenc

Stream mapping:
Stream #0:0 (h264) -> overlay:main (graph 0)
Stream #1:0 (srt) -> overlay:overlay (graph 0)
overlay (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (aac (native) -> aac (libvo_aacenc))

Press [q] to stop, [?] for help
sub2video: non-bitmap subtitle
frame= 1029 fps= 71 q=-1.0 Lsize=    4319kB time=00:00:43.17 bitrate= 819.6kbits/s
video:3612kB audio:675kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead:     
0.751962%
[libx264 @ 0x7fd082801200] frame I:44    Avg QP:17.59  size: 16172
[libx264 @ 0x7fd082801200] frame P:495   Avg QP:22.62  size:  5016
[libx264 @ 0x7fd082801200] frame B:490   Avg QP:23.28  size:  1027
[libx264 @ 0x7fd082801200] consecutive B-frames: 24.2% 34.4%  7.6% 33.8%
[libx264 @ 0x7fd082801200] mb I  I16..4: 27.2% 43.8% 28.9%
[libx264 @ 0x7fd082801200] mb P  I16..4:  5.9% 14.8%  2.9%  P16..4: 31.1% 10.7%  4.3%  0.0%  
0.0%    skip:30.3%
[libx264 @ 0x7fd082801200] mb B  I16..4:  0.2%  0.5%  0.2%  B16..8: 26.2%  3.3%  0.6%   
direct: 1.1%  skip:67.8%  L0:40.7% L1:52.4% BI: 6.9%
[libx264 @ 0x7fd082801200] 8x8 transform intra:57.6% inter:72.8%
[libx264 @ 0x7fd082801200] coded y,uvDC,uvAC intra: 41.3% 60.2% 22.0% inter: 9.1% 14.5% 0.6%
[libx264 @ 0x7fd082801200] i16 v,h,dc,p: 41% 25% 11% 22%
[libx264 @ 0x7fd082801200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 20% 23%  4%  5%  6%  5%  5%  4%
[libx264 @ 0x7fd082801200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 20% 12%  5%  8%  9%  7%  6%  4%
[libx264 @ 0x7fd082801200] i8c dc,h,v,p: 53% 20% 21%  6%
[libx264 @ 0x7fd082801200] Weighted P-Frames: Y:14.1% UV:9.9%
[libx264 @ 0x7fd082801200] ref P L0: 68.6% 14.5% 12.3%  4.2%  0.4%
[libx264 @ 0x7fd082801200] ref B L0: 91.7%  7.5%  0.8%
[libx264 @ 0x7fd082801200] ref B L1: 98.4%  1.6%
[libx264 @ 0x7fd082801200] kb/s:689.28

What am I doing wrong?

Jonathan_W
  • 275
  • 1
  • 3
  • 7

2 Answers2

15

sub2video: non-bitmap subtitle

That's your error. You have text-based subtitles, so you need to burn them with the subtitles filter.

ffmpeg -i input.mp4 -filter:v subtitles=subtitles.srt output.mp4

The overlay filter only works when your subtitles are images, which is the case for dvdsub, for example.

Furthermore, the problem seems to be that your subtitle file is not formatted correctly. Your time stamp definition contains an en-dash () instead of a normal minus-hyphen (-):

–->

Replace it with a correct minus-hyphen:

-->
slhck
  • 223,558
  • 70
  • 607
  • 592
  • @LordNeckbeard please see this pastebin with all details: http://pastebin.com/HYchEh3P – Jonathan_W Mar 03 '15 at 08:02
  • @LordNeckbeard or this one with more format details from ffprobe http://pastebin.com/V2ueiYWD – Jonathan_W Mar 03 '15 at 08:09
  • @Jonathan_W I could reproduce your issue, but your SRT file is not formatted correctly. For example, you're missing the actual subtitle for the first line. But even when correcting that, it doesn't work. There's definitely something wrong with your SRT file. (Maybe invisible characters? I don't know...) – slhck Mar 03 '15 at 08:32
  • @slhck strange - if I remove the first line, it doesn't process at all. Is it worth me sharing my ruby function to generate the srts ? And what would you recommend as a way to check for invisible characters? – Jonathan_W Mar 03 '15 at 09:22
  • Ruby file for creating subs here: http://pastebin.com/qXdG3Fzq – Jonathan_W Mar 03 '15 at 09:30
  • Thanks - I tried with another subs file, and it seems that is indeed the problem. Will investigate further. – Jonathan_W Mar 03 '15 at 09:36
  • @Jonathan_W Got it. You're using an en-dash instead of a normal hyphen when generating the timecodes. (Typical Mac issue, it's easy enough to fat-finger invisible non-breaking spaces or en/em-dashes. I've done it myself several times.) – slhck Mar 03 '15 at 09:36
  • Thanks man, I'd award 10 up votes if I could. That was literally weeks of pain :( – Jonathan_W Mar 03 '15 at 09:39
  • @Jonathan_W You're welcome, glad we got this solved! – slhck Mar 03 '15 at 09:41
  • The output MP4 from `ffmpeg -i input.mp4 -filter:v subtitles=subtitles.srt output.mp4` does not contain **any** subtitles, (Note: The SRT I use is verified to be OK. Besides, no errors are indicated from the above process. It seems it works but it doesn't. ) – Apostolos Aug 03 '23 at 21:23
  • @Apostolos Please ask a new question and include all the command output from ffmpeg you got. – slhck Aug 06 '23 at 06:51
  • Thanks, but I'm not posting anything in here anymore. I don't want to see another question of mine being downvoted as last time. I can only tell you that the ffmpeg process was completed successfully (with no error whatsoever). Simply, the subtitles were not embedded in the file. – Apostolos Aug 14 '23 at 23:02
  • @Apostolos I don't see why a reasonable question would be downvoted, and for ffmpeg type questions, as long as you provide the log, that should be fine. As far as I see you have one positive-scored question here. I can only encourage you to ask your question, otherwise nobody can help. – slhck Aug 16 '23 at 18:19
  • "Reasonable" is relative. What is reasonable for me may not be not reasonable for you or someone else. And from the little experience I have with this place (superuser.com, not stackoverflow) I have met a lot of *unreasonability* in it. Once, a workable and tested solution I provided using a reference, was downvoted and I received a comment saying that I should write a full answer and then add the reference! So, I added a full answer and asked to be upvoted, just to remove the downvote. The downvote was still there! After 10 days, I deleted the answer and decided not to write anything again. – Apostolos Aug 24 '23 at 11:02
  • @Apostolos I'm sorry to hear that you're demotivated. Sometimes downvotes appear for no particular or obvious reason, and some of them are not reverted even if you fix your post (it requires the original voter to go back and undo their vote). Don't sweat it. If you would like to solve your above problem, the only way is to ask a question. – slhck Aug 28 '23 at 09:24
  • Re:"Sometimes downvotes appear for no particular or obvious reason": Exactly. This happens a lot in stackoverflow.com and I have repeatedly mentioned that downvoting is a very bad and wrong system. **It doesn't help at all, no one**. What instead helps, everyone, is explaining with a comment what is wrong with an answer and why. And this is what I always do. **I never downvote**. Instead, I upvote a lot. So, as long as the administration cannot undestand this and downvoting is still offered as an option, I will not either ask a question or write an answer. – Apostolos Aug 29 '23 at 11:07
  • @slhck, thank you very much for your "moral" support on this subject! I have maybe dramatized it somehow. I don't really care. Besides, it's not me who loses, because I am a professional programmer since 1986 and I have posted quite a lot of useful answers in stackoverflow.com until now. (I have a 3,115-points reputation.) – Apostolos Aug 29 '23 at 11:14
0

you need a font config file, viz:

C:\WINDOWS\Fonts

mono monospace

sans-serif serif monospace sans-serif

Times Times New Roman serif Helvetica Arial sans Courier Courier New monospace serif Times New Roman sans Arial monospace Andale Mono Courier New monospace Courier monospace

save as fonts.xml in ffmpeg bin directory and refer to it in your batch/cml as

set FONTCONFIG_FILE=fonts.xml set FONTCONFIG_PATH=C:\Program Files\ffmpeg\bin

Mitch
  • 1
  • This might be helpful information, but as you can see from the answer that has already been posted and accepted, your post clearly does not answer the actual question. – music2myear Feb 27 '17 at 23:51
  • Please read the question again carefully. Your answer does **not** answer the original question. – DavidPostill Mar 05 '17 at 11:25