Add subtitles to trimmed mp4

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Add subtitles to trimmed mp4

FFmpeg-users mailing list
Hi people, I have a subtitle question; yay.

I have a 2 minute mp4 that I am going to trim using -ss and -to .

I have a SRT subtitle file with timings that will line up with the trimmed mp4.

If I try and trim the mp4 and add the subtitles at the same time, the trim is ignored and the whole media file is encoded.

ffmpeg -y -i /data/disposable/localised_20210212-1147-u81zpu/full_mp4.mp4 -ss 10 -to 40 -i https://somewhere/source/subtitles/subtitles.srt -filter_complex "[0:1]fifo[vout];[0:0]afifo[01_afifo]" -map "[vout]" -map "[01_afifo]" -map 1 -pix_fmt yuv420p -c:v libx264 -s 1920x1080 -profile:v high -level:v 4.1  -refs:v 2 -keyint_min 50 -b:v 15000k -r 25 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 48000 -b:a 192k -c:s:0 mov_text -metadata:s:s:0 language=eng -flags +global_header -f tee "[f=mp4:movflags=+faststart]/data/disposable/transcode_20210212-1147-znbqck/edit_2805.mp4"


If I add the -ss and -to command to the subtitle input file too, the output file has been trimmed, but the subtitles are out of sync. The subtitles stay locked to the time of the source media.

ffmpeg -y -i /data/disposable/localised_20210212-1147-u81zpu/full_mp4.mp4 -ss 10 -to 40 -i https://somewhere/source/subtitles/subtitles.srt -ss 10 -to 40 -filter_complex "[0:1]fifo[vout];[0:0]afifo[01_afifo]" -map "[vout]" -map "[01_afifo]" -map 1 -pix_fmt yuv420p -c:v libx264 -s 1920x1080 -profile:v high -level:v 4.1  -refs:v 2 -keyint_min 50 -b:v 15000k -r 25 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 48000 -b:a 192k -c:s:0 mov_text -metadata:s:s:0 language=eng -flags +global_header -f tee "[f=mp4:movflags=+faststart]/data/disposable/transcode_20210212-1147-znbqck/edit_2805.mp4"


Is there any way to force the subtitles in the SRT to be mapped to the time of the output?
I would prefer not to do it in two passes if possible.

I can include console output if it helps but I am pretty sure I am just putting the command together incorrectly and nothing untoward is happening.

Thanks in advance for your advice.

Adam

Sent from my iPhone
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Add subtitles to trimmed mp4

FFmpeg-users mailing list
adam smith via ffmpeg-user <[hidden email]> writes:

> Hi people, I have a subtitle question; yay.
>
> I have a 2 minute mp4 that I am going to trim using -ss and -to .
>
> I have a SRT subtitle file with timings that will line up with the trimmed mp4.
>
> If I try and trim the mp4 and add the subtitles at the same time, the trim is ignored and the whole media file is encoded.
>
> ffmpeg -y -i
> /data/disposable/localised_20210212-1147-u81zpu/full_mp4.mp4 -ss 10
> -to 40 -i https://somewhere/source/subtitles/subtitles.srt

I think you want to do

ffmpeg -y -ss 10 -t 30 -i input.mp4 -ss 10 -t 30 -i input.srt ...

See

https://ffmpeg.org/ffmpeg-all.html#toc-Main-options

Leo

> -filter_complex "[0:1]fifo[vout];[0:0]afifo[01_afifo]" -map "[vout]"
> -map "[01_afifo]" -map 1 -pix_fmt yuv420p -c:v libx264 -s 1920x1080
> -profile:v high -level:v 4.1 -refs:v 2 -keyint_min 50 -b:v 15000k -r
> 25 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 48000 -b:a 192k
> -c:s:0 mov_text -metadata:s:s:0 language=eng -flags +global_header -f
> tee
> "[f=mp4:movflags=+faststart]/data/disposable/transcode_20210212-1147-znbqck/edit_2805.mp4"

Do you mean to you `tee' with only one output sink?

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Add subtitles to trimmed mp4

FFmpeg-users mailing list


> On 13 Feb 2021, at 02:10, Leo Butler via ffmpeg-user <[hidden email]> wrote:
>
> I think you want to do
>
> ffmpeg -y -ss 10 -t 30 -i input.mp4 -ss 10 -t 30 -i input.srt ...
>
> See
>
> https://ffmpeg.org/ffmpeg-all.html#toc-Main-options <https://ffmpeg.org/ffmpeg-all.html#toc-Main-options>
>
> Leo

Thanks Leo.
I gave it a try but the same thing happened regarding the subtitle position and the in point of the media appeared less accurate and had black at the start.
I believe this is because -ss prior to the file path does a quick seek to the closest key frame to the desired timing, whereas -ss after the file path decodes all the data to find the actual specified timing.


>
>> -filter_complex "[0:1]fifo[vout];[0:0]afifo[01_afifo]" -map "[vout]"
>> -map "[01_afifo]" -map 1 -pix_fmt yuv420p -c:v libx264 -s 1920x1080
>> -profile:v high -level:v 4.1 -refs:v 2 -keyint_min 50 -b:v 15000k -r
>> 25 -ac 2 -bsf:a aac_adtstoasc -c:a libfdk_aac -ar 48000 -b:a 192k
>> -c:s:0 mov_text -metadata:s:s:0 language=eng -flags +global_header -f
>> tee
>> "[f=mp4:movflags=+faststart]/data/disposable/transcode_20210212-1147-znbqck/edit_2805.mp4"
>
> Do you mean to you `tee' with only one output sink?

My command is put together by a script I created and its configured to be able to write to multiple outputs, so tee is needed, in this test though I am only supplying a single output path and I didn’t write the script well enough to adapt the command. It doesn’t appear to do any harm, although you are right its a bit shit.


If you have any other ideas, keep them coming :)

Thanks
Adam

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Add subtitles to trimmed mp4

FFmpeg-users mailing list


> On 13 Feb 2021, at 10:46, adam smith via ffmpeg-user <[hidden email]> wrote:
>
> Thanks Leo.
> I gave it a try but the same thing happened regarding the subtitle position and the in point of the media appeared less accurate and had black at the start.
> I believe this is because -ss prior to the file path does a quick seek to the closest key frame to the desired timing, whereas -ss after the file path decodes all the data to find the actual specified timing.

Actually I think I may have just been a bit of a donut and you may be spot on.
Now I have had a cup of tea and woken up properly, I will do some more testing on different source formats and get back to you.

Thank you for your help, as always to everyone in the group it is very much appreciated.

Adam

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Add subtitles to trimmed mp4

FFmpeg-users mailing list
I have tested multiple source formats, I was totally wrong and Leo was bang on the money.
This is working great. I am able to concat multiple trimmed files together and the subtitles remain timed to the output - all is good and I am super happy.

Thanks Leo.
Adam

> On 13 Feb 2021, at 11:12, adam smith <[hidden email]> wrote:
>
> Actually I think I may have just been a bit of a donut and you may be spot on.
> Now I have had a cup of tea and woken up properly, I will do some more testing on different source formats and get back to you.
>
> Thank you for your help, as always to everyone in the group it is very much appreciated.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".