[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
FFMPEG code assistance.
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 25
Thread images: 5
File: Espolo (1).gif (348 KB, 612x792) Image search: [iqdb] [SauceNao] [Google]
Espolo (1).gif
348 KB, 612x792
Can I hardcode subtitles with ffmpeg?

I have the code for muxing the .mp4 and .srt, but iI have a version of Diablo, and it came with an srt of the non english parts only.

I want to hardcode these subtitles to be able to watch it without turning on subs at all.

and then I an mux the english subs as an option.

Pic unrelated, just some nice tequila.
>>
>>52916
Yes you can. You do it by re-encoding the video, and adding in the subtitles filter in the middle.

Be warned that the subtitles filter:

- doesn't use the standard escaping for parameters, so a some filenames that ffmpeg will accept, its subtitle filter won't
- will crash if you tell it there's subtitles when there's not
- can't just read the subtitles from the file; needs to be given the filename again, escaped differently to the way ffmpeg wants it
- will crash sometimes anyway
- is generally a PITA.

If you're going after MP4, then ffmpeg is still your best bet, but there's no way to give you a "just type this" command-line, because what you need to tell ffmpeg to do depends on the file, your fonts, and the phase of the moon.

Renaming the file to "/tmp/a.mp4" helps, as does using unix instead of Windows.
>>
>>52916
Like >>52992 mentioned, hardcoding subs means re-encoding the whole video. Yes, you can do this with FFmpeg.

To burn subtitles into a video you need to use the subtitles filter and the overlay filter. Here's an example with a filter expression to do this:
ffmpeg -i MOVIE.mp4 ... -filter_complex "subtitles=subs.srt[s],[0:v][s]overlay[v]" -map "[v]" -map "0:a" ... -c:a copy ... NEW_MOVIE.mp4
>>
>>53343
Alternatively, if you don't need to use any other filters in the chain, the filter expression itself can just be:
-vf "subtitles=subs.srt"
>>
ffmpeg -i MOVIE.mp4 ... -filter_complex "subtitles=subs.srt[s],[0:v][s]overlay[v]" -map "[v]" -map "0:a" ... -c:a copy ... NEW_MOVIE.mp4

I assume MOVIE.MP4 is input file
NEW_MOVIE.mp4 is output
and subs.srt is replaced with subtitle file,

but what are the ... for? mainly this one "0:a" ... -c:a?

I guessed reencoding would be needed (recreating the whole file with subs in it) and MP4 is fine for an end result. Ill just have to convert any MKV/AVI to MP4 first..
>>
File: Error.png (117 KB, 669x694) Image search: [iqdb] [SauceNao] [Google]
Error.png
117 KB, 669x694
Just tried this.
>>
>>53892
oh hello there, 'straya-boy, still trying to work through your collection?

that error is because, as the other people have mentioned above, specifying a filename within a video filter needs very specific escaping because both a backslash and a colon have very special meaning in a filter command (backslashes escape, colons separate filter arguments).

an easy way is to switch to unix notation and change all backslashes into forward slashes. that still leaves us with a colon though, wich we have to double-escape with two backslashes, like this:

-filter_complex "subtitles=D\\:/Utorrent Downloads/Diablo/Diablo.srt"

i last worked with subtitles half a year ago, but afaik you don't need to do the overlay stuff, that's only for certain kinds of DVD subtitles which are actually saved as images, not as text.

the "..." this guy >>53343 used are probably for your standard commands that control codecs (c:v, etc) and quality (bitrate, crf, etc). i guess they only showed you how the subtitle filter works, since what you do with it is up to you.

mapping is generally not required in simple files that have 1 video, 1 audio and 1 subtitle going in and and coming out. -map is used to tell it which streams to put. the first -map is for the first stream (stream 0). notation is file:stream so 0:1 would take the second stream of the first file (ie the audio stream = 0:a) and map it as the first output stream (stream 0). if it doesn't work automatically you'd want to do -map 0:v -map 0:a -map 1:s

when i last worked with subtitles there were some quirky things. the filter only uses SSA/ASS subtitles (because they have fonts and positions specified), but can on-the-fly convert SRT - only they look awful unless you specify fonts and sizes in the filter, which meant you'd have to setup a fonts.conf for ffmpeg... get back if you want further help. i used to write tutorials, i have it all typed out somewhere...
>>
oh yeah, just in general. the ffmpeg documentation is actually really good. the subtitle filter is a bit of an odd one out, since it's a bitch to use and all the styles you can specify come from SSA/ASS and not ffmpeg (so they aren't documented), but most of your questions about features you can look up here

http://ffmpeg.org/ffmpeg.html
http://ffmpeg.org/ffmpeg-filters.html
>>
>>53892
Heyyy it's Jacob. Hope you're doing mate.
>>
File: image.jpg (32 KB, 362x362) Image search: [iqdb] [SauceNao] [Google]
image.jpg
32 KB, 362x362
>>54076
doing well*
>>
>>54076
>>54192
HOW DO YOU KNOW MY NAME??????
lol
Yeah doin well ol buddy ol pal,

>>54058
And tickin along slowly, my 'merry can mate.

Slowly reading through those links you provided, trying to get my head wrapped around it all.

Was looking into ssa/ass subs but it seemed too in depth needing to specify fonts sizes etc, so I was hoping I can find a way to just overlay the srt straight to the video.
>>
>>54058
>specifying a filename within a video filter needs very specific escaping because both a backslash and a colon have very special meaning in a filter command
Did I mention I hate ffmpeg?

It makes it near-impossible to script, because *everything else in the entire Windows ecosystem* uses backslash as a path separator, so every path it will ever encounter has characters in that need to be escaped in ffmpeg's own peculiar way.

The simplest solution to ffmpeg's twattery is to symlink or copy every file to a plain filename in the working directory, using a non-retarded tool that accepts normal filenames.
>>
>>54631
>Was looking into ssa/ass subs but it seemed too in depth needing to specify fonts sizes etc, so I was hoping I can find a way to just overlay the srt straight to the video.

yeah, it's not necessary, but it really makes them look nice.

my standard hardcoding command snippet looks like this:
-filter_complex "subtitles=input.srt:force_style='FontName=Arial,FontSize=28,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BackColour=&H80000000,BorderStyle=1,Outline=2,Shadow=1'"

anyway, i hope you've already set up some ~5 MB test files, because trying to learn hardcoding on a full 720p movie seems just horrible...

>>54631
>HOW DO YOU KNOW MY NAME??????
you've been posting screens where your windows user name is visible all along. makes it easy to spot you across threads...
>>
>>54677
HA yeah, its prettyy complex when you want to do more than change a container or attach subs..

>>54687
Yeah I knew I left my name in the pictures, i was joking lol. But its only my second or third thread! unless someone has been trolling? haha.

anyway.

First, can I do this regardless of the extension (mp4/avi/mkv) on best for a specific one?

and
Where in the line do I add your snip of script?

ffmpeg -i INPUTMOVIE.mp4 -c:v copy -filter_complex "subtitles=input.srt:force_style='FontName=Arial,FontSize=28,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BackColour=&H80000000,BorderStyle=1,Outline=2,Shadow=1'" -c:a copy NEW_MOVIE.mp4

Somthing like that? Im about to try it anyway, but what might I need to adjust
>>
>>54703
the extension doesn't matter as it only tell you the container. it has nothing to do with the contents. you can have x264-encoded video in mp4 or in mkv containers and it would make no difference to the video quality or speed or anything...

where you put the filters in the command line is irrelevant as long as -i is at the start and output is last.

your line won't work. if you want to hardcode subtitles you can't -c:v copy - you need to re-encode the whole video stream! (hence why you should experiment with small test files) if you want to do it blindly and pray it does a decent job, you can just leave -c:v unspecified, but at some point you probably want to start to get into the details of codecs and quality control.

for your offline needs you'd probably only need the x264 codec, which has pretty good default values anyway (completely unlike VP8 which you need for 4chan-compatible webms and has garbage default values). if you are unsatisfied with the default quality output you might want to adjust -crf. the default value is 23, lower means better quality, roughly every 6 steps away from 23 double or half the bitrate of the final product. example:
-i input.mp4 -c:v libx264 -crf 21 -filter_complex "..." -c:a copy output.mp4
>>
>>54706
I got called away so i didnt get to try that lne I put above anyway, but good point I didnt think when i put in -c:v copy, thats just going to copy the video..

Its head fucking enough, ill just try it on the fly with the files, it keeps all originals anyway..

ok ill edit and try some versions and see how I go.
>>
File: INVALID ARGUMENT.png (73 KB, 669x336) Image search: [iqdb] [SauceNao] [Google]
INVALID ARGUMENT.png
73 KB, 669x336
So, i tried again and noticed somthing in the errors...

Other than the hilarious "Invalid Argument" (I have a potato, your argument is invalid)

It was trying to use Utorrent from the file name as some sort of command it didnt like.

So i copied the 2 files to the bin folder and simplified the names, and re edited the script.. it seems to be working now, ticking away with a usual reformatting looking way..

a little slow, but im in no big rush anyway...

be back with an update shortly.....
>>
>>54712
>It was trying to use Utorrent from the file name as some sort of command it didnt like.

yeah, probably some problem with the escaping as previously mentioned.

eg: -filter_complex "size=640:480" means: apply the size filter with width 640 and hight 480.
if the file path is escaped incorrectly then it thinks -filter_complex "subtitles=D:\Utorrent" means apply the subtitle filter with file path D and original_size Utorrent
>>
File: YISSS!!!!!.png (781 KB, 1281x573) Image search: [iqdb] [SauceNao] [Google]
YISSS!!!!!.png
781 KB, 1281x573
>>54718
Aha, and can I change that size to 1280 and make it higher resolution too?

Also this worked......

Copied files to bin folder, simplified the names for ease of entering into the script and used the following.

ffmpeg -i input.mp4 -filter_complex "subtitles=input.srt:force_style='FontName=Arial,FontSize=28,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BackColour=&H80000000,BorderStyle=1,Outline=2,Shadow=1'" -c:a copy output.mp4

see pic related

took a while, about 2-3 seconds of the movie formatted per second but thats ok.
>>
>>54720
you could, but upscaling doesn't make it magically a better quality than the source material. unless you are trying to match different clips to the same size (for some further editing for example) upscaling is almost never a good idea. it just adds file size without providing anything the built-in upscaler in your video player can't do anyway.
>>
>>54723
OK, thought that would be the case.

Have noticed after my playing they come out with a higher total bitrate though.

Well, I have nailed it.

Hardcoded subs DONE

Just had a quick edit of the other english subs, and cut out the non english parts to stop it doubling up

Then remuxed with the .srt attached.

Fuck I love finally figuring this shit out, makes me feel like a proper nerd LOL!
>>
i'd like to hijack this thread for a moment and ask, can subtitles be edited? as in changing the text or maybe even adding in pictures
>>
>>54771
yep, dont know about adding pictures, but editing is possible.

google it and you will get some answers pretty fast.

I did it earlier using notepad ++, just removed some lines I didnt need.
>>
>>54771
it depends. if the subtitles are just text (so called "soft subs", eg .srt, .ass, etc) then yes. as >>54799 mentioned, they are just plain text and can be edited in any text editor.

SRT has a very simple structure of just time codes and lines.
ASS has a very complicated structure with styles, fonts, colours, positions, rotations, etc... (hence why it is so popular for anime subs, karaoke, etc). you can edit them by hand, but it might be very tedious or unclear.

if you're looking for a great free tool to edit and time subtitiles i can recommend Aegisub (aegisub.org). it's the defacto standard for editing and timing ASS subtitles.

if we're talking about actual DVD subtitles (.idx and .sub) then no. you would need to convert them to text first (which is why you'll often find soft subs for movies on the internet that confuse small L with big i - the automatic converter used just sees a line and doesn't care which character it is in the context of the word).
>>
>>54799
>>54812
Thanks guys, looked into it and tried out SubtitleEdit for SRTs and Aegisub for ASS, both work great.
Thread replies: 25
Thread images: 5
Thread DB ID: 502951



[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.