Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Adding subtitles to a video

  1. #1
    Join Date
    May 2012
    Beans
    367

    Adding subtitles to a video

    Hello everybody,

    I've got a text file which has some words (subtitles), and I would like to merge it with a video using FFMPEG, is there any way to do so??

    Thanks in advance

  2. #2
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Adding subtitles to a video

    What find of subtitles? What does ffmpeg say about your video and the subtitle file? Something like:

    Code:
    ffmpeg -i input.mp4 -i subtitles.srt

  3. #3
    Join Date
    May 2012
    Beans
    367

    Re: Adding subtitles to a video

    This is the result:

    Code:
    ffmpeg version 0.8.9-6:0.8.9-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
      built on Nov  9 2013 19:15:53 with gcc 4.7.2
    *** THIS PROGRAM IS DEPRECATED ***
    This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Q_hyCryvyuk.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: isommp42
        creation_time   : 2013-11-30 04:32:53
      Duration: 00:04:44.81, start: 0.000000, bitrate: 360 kb/s
        Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 480x360, 262 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc
        Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 96 kb/s
        Metadata:
          creation_time   : 2013-11-30 04:32:53
    [srt @ 0x8d14ca0] Estimating duration from bitrate, this may be inaccurate
    Input #1, srt, from 'Q_hyCryvyuk.srt':
      Duration: N/A, start: 32.956000, bitrate: N/A
        Stream #1.0: Subtitle: srt
    At least one output file must be specified

  4. #4
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan Norwich
    Beans
    2,326
    Distro
    Lubuntu 22.04 Jammy Jellyfish

    mencoder subtitles, mencoder srt,

    you can also use mencoder for this

    Code:
    mencoder -sub file.srt   -subfont-outline 4    -subcp iso-8857-9 -ovc x264 -oac copy   -o filewithsub.mp4 originalfile.mp4
    Last edited by shantiq; December 7th, 2013 at 02:25 PM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community ie 50 brains are better than one
    Playing with Slackware too now ...
    ShanArt

  5. #5
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Adding subtitles to a video

    Do you want to hardsub (burn in the subtitles; requires re-encoding) or use softsubs (any sane player will be able to choose the subtitle stream; no re-encoding required)?

  6. #6
    Join Date
    May 2012
    Beans
    367

    Re: Adding subtitles to a video

    @shantiq: This the result:
    Code:
    $ mencoder -sub Q_hyCryvyuk.srt -subfont-outline 4 -subcp iso-8857-9 -ovc x264 -oac copy -o Q_hyCryvyukBurned.mp4 Q_hyCryvyuk.mp4 
    MEncoder svn r34540 (Ubuntu), built with gcc-4.7 (C) 2000-2012 MPlayer Team
    
    WARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.
    success: format: 0  data: 0x0 - 0xc3ee3d
    libavformat version 53.21.1 (external)
    Mismatching header version 53.19.0
    libavformat file format detected.
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (aac), -aid 0, -alang und
    VIDEO:  [H264]  480x360  24bpp  25.000 fps  262.2 kbps (32.0 kbyte/s)
    [V] filefmt:44  fourcc:0x34363248  size:480x360  fps:25.000  ftime:=0.0400
    Opening video filter: [expand osd=1]
    Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
    SUB: error opening iconv descriptor.
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
    libavcodec version 53.35.0 (external)
    Mismatching header version 53.32.2
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    Audio format 0x4134504d is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.
    
    Exiting...
    @FakeOutdoorsman:

    hardsub will burn them, if there are more than 1 subtitle we need to re-encode the video many times, how about softsubs, can we choose the subtitle that we need???

    What is the command line for hardsub, I used:

    Code:
    ffmpeg -i Q_hyCryvyuk.mp4 -i Q_hyCryvyuk.srt -acodec copy -c:s mov_text -slang eng -vcodec libx264 -profile:v high -level:v 4.0 output.mp4
    result:

    Code:
    Unrecognized option 'c:s'
    Failed to set value 'mov_text' for option 'c:s'

  7. #7
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Adding subtitles to a video

    I see two issues here:

    1. Softsub support in mp4 is generally crappy. Using mkv would be a better choice, but if you need mp4 it can probably be used but some features (like italics, etc) from the srt file will be missing since you have to use mov_text (as far as I know).
    2. The "ffmpeg" in the repository is crappy. It is from a fork, not from FFmpeg, and this fake version is old, buggy, and lacks some subtitle features.


    My examples here will not work with the fake so-called ffmpeg from the repository. You'll have to get the real ffmpeg. You can:



    hardsubs

    To burn-in hardsubs with ffmpeg see: How to burn subtitles into the video. You'll have to use the real ffmpeg for this to work.

    softsubs

    You'll have to use the real ffmpeg for this to work.

    For softsubs you do not need to encode the video or the audio. Example for mp4:
    Code:
    ffmpeg -i movie.mkv -i englishsubs.srt -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng mov_text.mp4
    Example for mkv:
    Code:
    ffmpeg -i movie.mkv -i englishsubs.srt -c copy -metadata:s:s:0 language=eng mov_text.mkv
    Example for more languages:
    Code:
    ffmpeg -i movie.mkv -i englishsubs.srt -i frenchsubs.srt -map 0 -map 1 -map 2 -c copy -metadata:s:s:0 language=eng -metadata:s:s:1 language=fra subtitles.mkv
    By default, ffmpeg includes only one stream of each type (video, audio, subtitle) present in the input files and adds them to each output file (see stream selection). Since you now have two subtitles you have to explicitly tell ffmpeg to include all files from each input with -map.
    Last edited by FakeOutdoorsman; December 10th, 2013 at 08:03 PM.

  8. #8
    Join Date
    May 2012
    Beans
    367

    Re: Adding subtitles to a video

    I used this command line, but still getting the same error:

    Code:
    $ ffmpeg -i Q_hyCryvyuk.mkv -i Q_hyCryvyuk.srt -vcodec copy -acodec copy -c:s mov_text -metadata:s:s:0 language=eng mov_text.mp4
    ffmpeg version 0.8.9-6:0.8.9-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
      built on Nov  9 2013 19:15:53 with gcc 4.7.2
    *** THIS PROGRAM IS DEPRECATED ***
    This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
    [matroska,webm @ 0x82cb880] Estimating duration from bitrate, this may be inaccurate
    Input #0, matroska,webm, from 'Q_hyCryvyuk.mkv':
      Metadata:
        MAJOR_BRAND     : mp42
        MINOR_VERSION   : 0
        COMPATIBLE_BRANDS: isommp42
        CREATION_TIME   : 2013-11-30 04:32:53
        ENCODER         : Lavf53.21.1
      Duration: 00:04:44.83, start: 0.000000, bitrate: 192 kb/s
        Stream #0.0(und): Video: mpeg4 (Simple Profile), yuv420p, 480x360 [PAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1k tbn, 25 tbc (default)
        Stream #0.1(und): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
        Metadata:
          CREATION_TIME   : 2013-11-30 04:32:53
          LANGUAGE        : und
    [srt @ 0x83012c0] Estimating duration from bitrate, this may be inaccurate
    Input #1, srt, from 'Q_hyCryvyuk.srt':
      Duration: N/A, start: 32.956000, bitrate: N/A
        Stream #1.0: Subtitle: srt
    Unrecognized option 'c:s'
    Failed to set value 'mov_text' for option 'c:s'

  9. #9
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan Norwich
    Beans
    2,326
    Distro
    Lubuntu 22.04 Jammy Jellyfish

    Re: Adding subtitles to a video

    Code:
    Audio format 0x4134504d is incompatible with '-oac copy', please try '-oac pcm' instead
    mp4 sometimes needs this with mencoder


    mencoder -sub file.srt -subfont-outline 4 -subcp iso-8857-9 -ovc x264 -oac pcm -o filewithsub.mp4 originalfile.mp4

    Last edited by shantiq; December 9th, 2013 at 05:06 PM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community ie 50 brains are better than one
    Playing with Slackware too now ...
    ShanArt

  10. #10
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Adding subtitles to a video

    Quote Originally Posted by alfirdaous View Post
    I used this command line, but still getting the same error:
    My commands are for ffmpeg from FFmpeg.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •