ffmpeg.wasm: -vf subtitles=example.srt not work

how can i insert .srt format subtitle into mp4 video ?

ffmpeg.run('-i', 'output.mp4', '-vf', 'subtitles=xxx.srt', this.output)

not work

should compile ffmpeg.wasm with --enable-filter=subtitles ?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 25

Most upvoted comments

Hi @kkxlkkxllb . I’m glad It compiled nicely. I have one more tip for you. You will need to upload the font file you want to use on your subtitles and then specify it on your command. I’m away from the computer, but as soon as possible, I’ll share some code to show how I’m doing.

Here is the example code:

ffmpeg.FS('writeFile', 'output.mp4', YourVideoFile);
ffmpeg.FS('writeFile', 'xxx.srt', YourSubtitleFile);
ffmpeg.FS('writeFile', `tmp/arial`, Arial.ttf); 

ffmepg.run('-i', 'output.mp4', '-vf', 'subtitles=xxx.srt:fontsdir=/tmp:force_style="Fontname=Arial"', this.output);

Thanks @loe-lobo , the PR has been merged and this feature is included in release v0.9.8. 😄

Is there an issue with how I’m loading and naming the font?

I got it working with another font, but I think it was just an issue with the Fontname.

fmpeg.FS(
			'writeFile',
			'tmp/SourceSansPro-Bold',
			await fetchFile( '/path/to/SourceSansPro-Bold.ttf' )
		);
...
'subtitles=captions.vtt:fontsdir=/tmp:force_style=\'Fontname=Source Sans Pro\''

@allilevine I have save problem too. Arial is working, but other font not work. Have you found a solution?

@ImmortalZ What error are you getting? In my case it was a mismatch between the actual font name and the Fontname I was indicating. “Source Sans Pro” worked.

@allilevine Thank you for your help


2022.5.11 my problem has been solved Fontname use this: image

code

Fontname must be single quotes image

Is there an issue with how I’m loading and naming the font?

I got it working with another font, but I think it was just an issue with the Fontname.

fmpeg.FS(
			'writeFile',
			'tmp/SourceSansPro-Bold',
			await fetchFile( '/path/to/SourceSansPro-Bold.ttf' )
		);
...
'subtitles=captions.vtt:fontsdir=/tmp:force_style=\'Fontname=Source Sans Pro\''

I’m glad it worked in the end, usually it’s something related with the font name. Fontname=abel-v12-latin-regular might not be the correct Fontname to be used, did you try Fontname=Abel ? I think it should work.

Is there an issue with how I’m loading and naming the font?

I got it working with another font, but I think it was just an issue with the Fontname.

fmpeg.FS(
			'writeFile',
			'tmp/SourceSansPro-Bold',
			await fetchFile( '/path/to/SourceSansPro-Bold.ttf' )
		);
...
'subtitles=captions.vtt:fontsdir=/tmp:force_style=\'Fontname=Source Sans Pro\''

@loe-lobo can you create a PR to https://github.com/ffmpegwasm/ffmpeg.wasm-core? So that I can merge it and publish a new version of ffmpeg.wasm-core.

BTW, I checked your commits already and I think they are amazing 😄