I am trying to add a subtitle to a video using ffmpeg and a .srt
file. Using the command:
ffmpeg -i videopath.mp4 -i subtitlefilepath.srt -c:v libx264 -preset ultrafast -ar 44100 -ac 2 -ab 128k -strict -2 videooutput.mp4
.srt
file looks like
1
00:00:00,30-->00:00:05,30
Sample sub title for video
What is that 30 after duration
?
Output:
ffmpeg version git-2013-12-11-3b28564 Copyright (c) 2000-2014 the FFmpeg developers built on Jan 22 2014 13:22:00 with gcc 4.6 (GCC) 20120106 (peelease) configuration: --arch=arm --target-os=linux --enable-cross-compile --cross-prefix=/Users/sunitha/Downloads/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi- --prefix=../build --sysroot=/Users/sunitha/Downloads/android-ndk-r9c/platforms/android-9/arch-arm --extra-cflags=' -I/Users/sunitha/Downloads/android-ndk-r9c/platforms/android-9/arch-arm/usr/include -I../libmp3lame/include -I../libx264/include -DANDROID -marm -march=armv6 ' --extra-ldflags=' -L/Users/sunitha/Downloads/android-ndk-r9c/platforms/android-9/arch-arm/usr/lib -L../libmp3lame/lib -L../libx264/lib' --disable-debug --enable-libmp3lame --enable-libx264 --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avfilter --enable-decoders --enable-demuxers --enable-encoders --enable-filters --enable-indevs --enable-network --enable-parsers --enable-protocols --enable-swscale --enable-gpl --enable-nonfree
libavutil 52. 63.100 / 52. 63.100
libavcodec 55. 48.102 / 55. 48.102
libavformat 55. 25.101 / 55. 25.101
libavdevice 55. 5.102 / 55. 5.102
libavfilter 4. 1.100 / 4. 1.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/20141022_125926.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2014-10-22 07:29:39
Duration: 00:00:08.58, start: 0.000000, bitrate: 11752 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1280x720, 11758 kb/s, 29.33 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 90
creation_time : 2014-10-22 07:29:39
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 60 kb/s (default)
Metadata:
creation_time : 2014-10-22 07:29:39
handler_name : SoundHandle
Input #1, srt, from '/storage/emulated/0/DCIM/Camera/subtitle.srt': Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: subrip
[libx264 @ 0x11cf050] using cpu capabilities: ARMv6 NEON[libx264 @ 0x11cf050] profile Constrained Baseline, level 3.1
[libx264 @ 0x11cf050] 264 - core 140 r2377 1ca7bb9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to '/storage/emulated/0/VideoOverLay/videooverlay1413965066659.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
encoder : Lavf55.25.101
Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 15360 tbn, 30 tbc (default)
Metadata:
rotate : 90
creation_time : 2014-10-22 07:29:39
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2014-10-22 07:29:39
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.47 bitrate= 0.8kbits/s
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.91 bitrate= 0.4kbits/s
frame= 3 fps=1.2 q=23.0 size= 38kB time=00:00:01.00 bitrate= 311.9kbits/s
frame= 6 fps=1.9 q=22.0 size= 7
10-22 13:35:08.365: D/dalvikvm(1754): GC_CONCURRENT freed 1968K, 26% free 16486K/22120K, paused 14ms+6ms, total 59ms
10-22 13:35:08.365: I/exit code >>>>>>>>..(1754): 0
10-22 13:35:08.365: I/exit code >>>>>>>>..(1754): 0
I can't see any subtitles on the video. Where's the problem?
You're not telling ffmpeg to use the subtitles. With multiple inputs ffmpeg will only map one, IIRC:
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> aac)
So try something like:
ffmpeg -i videopath.mp4 -i subtitlefilepath.srt \
-c:v libx264 -preset ultrafast \
-ar 44100 -ac 2 -ab 128k -strict -2 \
-c:s mov_text -map 0 -map 1 \
videooutput.mp4
This would copy the subtitles as-is and map the input video (-map 0
) and subtitle file (-map 1
) to the output. You should see something like this:
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> aac)
Stream #1:0 -> #1:0 (srt -> mov_text)
You could also use the subtitles
filter to hardcode subs. For that you need to compile ffmpeg version with libass
though, which is not the case for the one you're using.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments