Results 1 to 8 of 8

Thread: offsetting a subtitle in a video using ffmpeg

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

    offsetting a subtitle in a video using ffmpeg

    been reading around and finding no joy thus far
    i do not suppose it is all that difficult once you know as most things

    I have a video in mp4 in German I have an ENG srt 1.mp4 1.srt they are separate files

    I want to mux them with the srt as default but not burnt-in and export to an mkv

    MY specific request here is to offset the sub by -32000 ms

    Tried a few things not as yet got it this is the best i have found but it does not do it maybe the -c copy not sure maybe the way the timing is written here anyway the syntax is off

    Code:
    ffmpeg -i 1.mp4 -itsoffset 0.32 -i 1.srt -c copy  1.mkv

    EDIT

    a bit of further study yielded the answer: [CTRL-F enter offset]

    Code:
    ffmpeg -i 1.mp4 -itsoffset -00:00:32 -i  1.srt -map 0 -map 1  -c:v copy output.mkv
    obviously use 00:00:00 and not -00:00:00 if you want to offset the other way
    NB the offset applies to files which follow so to make sure the order is respected



    will mark as solved
    Last edited by shantiq; May 22nd, 2021 at 09:52 AM.
    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

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

    Re: offsetting a subtitle in a video using ffmpeg

    I have one more question here

    I realize the video has the srt in the correct place but it is a default sub not burnt-in and i wish for for it to be burnt-in
    How can i combine the offset and the burnt-in option? (-vf subtitles=1.srt) they seem to antagonize each other
    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

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: offsetting a subtitle in a video using ffmpeg

    Perhaps you can edit the SRT file with a tool like https://subtitletools.com/subtitle-sync-shifter. This changes all the timestamps in the SRT file to include a fixed offset. Then you could mux the edited SRT file with the video and not need to use itsoffset.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

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

    Re: offsetting a subtitle in a video using ffmpeg

    Quote Originally Posted by SeijiSensei View Post
    thank you Seiji feels like cheating but saves a lot of time
    ACE TIP!
    Last edited by shantiq; May 22nd, 2021 at 02:32 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
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: offsetting a subtitle in a video using ffmpeg

    mkvmerge can do this too - or the GUI version - mkvtoolnix-gui. Great when you want to shift video, audio, or subtitles and know the offsets already.
    If you don't know, then there are a number of subtitle (really caption) tools. It gets more complex if the frame rates cause misalignment for the subtitles, getting worse and worse through the entire video.

    The great thing about mkv files is that we can toggle a forced-on subtitle for a specific language, but still have 10 other languages supported which can be swapped in through the player's GUI. I'm not a fan of burning captions into the video, but I've also gone out of my way to ensure all my playback devices can handle both internal and external SRT files.

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

    Re: offsetting a subtitle in a video using ffmpeg

    Quote Originally Posted by TheFu View Post
    mkvmerge
    Thank you TheFu had already started horsing around a bit with mkvmerge also with HandBrakeCLI to find that HandBrakeCLI did not like the concept of external srt to burn in unless i messed up
    Handbrake GUI worked but it stops offset at -30000 or rounds it up so no good to me here [needed -32000]....
    With mkvextract/mkvmerge I had all the files separated and then reassembled but the offset was not happening for me

    Anyway then Seijisensei offered his celeritous escape/shortcut and i went for that

    PS : I do not either usually burn but this was for Youtube which the way I understand it only accepts burnt-in or separate with the option to move EACH line but not offset the entire file timings or maybe i missed that.

    PS2: Would love to know how mkvmerge can shift ALL timestamps in one go as cannot see it in the manual; if anyone knows and has the time to explain; but no hurry as task i wanted was done
    Will have a play with GUI (hmm gave me no joy got a file produced but srt was all in the wrong place not sure what happened)

    Thanx to all for great input
    Last edited by shantiq; May 23rd, 2021 at 08:56 AM.
    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

  7. #7
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: offsetting a subtitle in a video using ffmpeg

    subtitleeditor is another option. I've used it when I was desperate. From time to time, I've written a little perl program that used the "Subtitles" module to have complete control over the times. https://metacpan.org/pod/Subtitles The problem I've had is that it doesn't support .ass captions. That isn't a joke. It is a real type of caption format.

  8. #8
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: offsetting a subtitle in a video using ffmpeg

    Quote Originally Posted by shantiq View Post
    thank you Seiji feels like cheating but saves a lot of time
    ACE TIP!
    You're welcome. I've found there's usually some way to solve most problems like these. Just takes a bit of Googling.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Tags for this Thread

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
  •