[Libav-user] Muxing a .srt file into a .mp4 file ?

pehache pehache.7 at gmail.com
Sun Apr 22 16:22:03 CEST 2012


Hi,

Now that my multiple audio tracks issue is fixed, I face another one : I 
have one the one hand a video in a mp4 file, and on the other hand 
subtitles in a .srt file, and I want to mux them into a single file 
(either .mp4 or .mkv)

The MPEG-4 standard says that the subtitle format retained for .mp4 
files is the "mpeg-4 timed text" : it looks very similar to the SRT 
format, but is it really the same ?
http://en.wikipedia.org/wiki/MPEG-4_Part_17

Here is what happens if I try to mux into a mp4 file, simply copying the 
subtitles (seems that it can not interpret the .srt file ?)

===================================================================
*****$ ffmpeg -i Good_Bye_Lenin.DVDRIP.HQ.deFR.mp4 -i 
Good_Bye_Lenin.de.srt -vcodec copy -acodec copy -scodec copy -map 0.0 
-map 0.1 -map 1.0 -y toto.mp4
ffmpeg version 0.7.11, Copyright (c) 2000-2011 the FFmpeg developers
   built on Mar 17 2012 12:11:52 with gcc 4.2.1 (Apple Inc. build 5666) 
(dot 3)
   configuration: --prefix=/opt/local --enable-gpl --enable-postproc 
--enable-swscale --enable-avfilter --enable-libmp3lame 
--enable-libvorbis --enable-libtheora --enable-libdirac 
--enable-libschroedinger --enable-libopenjpeg --enable-libxvid 
--enable-libx264 --enable-libvpx --enable-libspeex 
--mandir=/opt/local/share/man --enable-shared --enable-pthreads 
--cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
   libavutil    50. 43. 0 / 50. 43. 0
   libavcodec   52.123. 0 / 52.123. 0
   libavformat  52.111. 0 / 52.111. 0
   libavdevice  52.  5. 0 / 52.  5. 0
   libavfilter   1. 80. 0 /  1. 80. 0
   libswscale    0. 14. 1 /  0. 14. 1
   libpostproc  51.  2. 0 / 51.  2. 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x102052000] max_analyze_duration 5000000 
reached at 5013333

Seems stream 0 codec frame rate differs from container frame rate: 
180000.00 (180000/1) -> 25.00 (25/1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Good_Bye_Lenin.DVDRIP.HQ.deFR.mp4':
   Metadata:
     major_brand     : mp42
     minor_version   : 0
     compatible_brands: mp42isomavc1
     creation_time   : 2012-04-07 09:59:01
     encoder         : HandBrake 0.9.6 2012022800
   Duration: 01:52:41.32, start: 0.000000, bitrate: 1274 kb/s
...
     Stream #0.0(und): Video: h264 (High), yuv420p, 704x384, 999 kb/s, 
25 fps, 25 tbr, 90k tbn, 180k tbc
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.1(fra): Audio: aac, 48000 Hz, stereo, s16, 131 kb/s
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.2(deu): Audio: aac, 48000 Hz, stereo, s16, 131 kb/s
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.3(fra): Subtitle: dvdsub, 4 kb/s
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.4(und): Subtitle: text / 0x74786574
     Metadata:
       creation_time   : 2012-04-07 09:59:01
[srt @ 0x102053200] Estimating duration from bitrate, this may be inaccurate
Input #1, srt, from 'Good_Bye_Lenin.de.srt':
   Duration: N/A, start: 39.783000, bitrate: N/A
     Stream #1.0: Subtitle: srt
[mp4 @ 0x102056e00] track 2: could not find tag, codec not currently 
supported in container
Output #0, mp4, to 'toto.mp4':
   Metadata:
     major_brand     : mp42
     minor_version   : 0
     compatible_brands: mp42isomavc1
     creation_time   : 2012-04-07 09:59:01
     encoder         : Lavf52.111.0
...
     Stream #0.0(und): Video: libx264, yuv420p, 704x384, q=2-31, 999 
kb/s, 90k tbn, 90k tbc
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.1(fra): Audio: aac, 48000 Hz, stereo, 131 kb/s
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.2: Subtitle: srt
Stream mapping:
   Stream #0.0 -> #0.0
   Stream #0.1 -> #0.1
   Stream #1.0 -> #0.2
Could not write header for output file #0 (incorrect codec parameters ?)
===================================================================


Now without telling anything about the subtitle codec (don't understand 
the error):

===================================================================
*****$ ffmpeg -i Good_Bye_Lenin.DVDRIP.HQ.deFR.mp4 -i 
Good_Bye_Lenin.de.srt -vcodec copy -acodec copy -map 0.0 -map 0.1 -map 
1.0 -y toto.mp4

[SNIP]

[srt @ 0x102053200] Estimating duration from bitrate, this may be inaccurate
Input #1, srt, from 'Good_Bye_Lenin.de.srt':
   Duration: N/A, start: 39.783000, bitrate: N/A
     Stream #1.0: Subtitle: srt
Number of stream maps must match number of output streams
===================================================================


Note that with a .mkv output file, this latter command fails as well 
with a different error message :

===================================================================
*****$ ffmpeg -i Good_Bye_Lenin.DVDRIP.HQ.deFR.mp4 -i 
Good_Bye_Lenin.de.srt -vcodec copy -acodec copy -map 0.0 -map 0.1 -map 
1.0 -y toto.mkv

[SNIP]

Output #0, matroska, to 'toto.mkv':
     Stream #0.0(und): Video: libx264, yuv420p, 704x384, q=2-31, 999 
kb/s, 90k tbn, 90k tbc
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.1(fra): Audio: aac, 48000 Hz, stereo, 131 kb/s
     Metadata:
       creation_time   : 2012-04-07 09:59:01
     Stream #0.2: Subtitle: [0][0][0][0] / 0x0000, 64 kb/s
Stream mapping:
   Stream #0.0 -> #0.0
   Stream #0.1 -> #0.1
   Stream #1.0 -> #0.2
Encoder (codec id 94210) not found for output stream #0.2
===================================================================


And finally, the only command which succeeds is with the output .mkv 
file, and specifying -scodec copy:

===================================================================
*****$ ffmpeg -i Good_Bye_Lenin.DVDRIP.HQ.deFR.mp4 -i 
Good_Bye_Lenin.de.srt -vcodec copy -acodec copy -map 0.0 -map 0.1 -map 
1.0 -y toto.mkv
===================================================================



So.... is there a way to include SRT subtitles into MP4 files ? Or is 
the MKV format the only way to go ?

Thanks,




More information about the Libav-user mailing list