当前位置:网站首页>Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code

Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code

2022-06-25 09:28:00 Maoningyi

Click to view the video course ↓↓↓

fcpx Quickly add subtitles | final cut pro Import fcpxml The subtitle file does not match the video time ? I'll show you a way to get it done

Hello everyone , I'm Ning Yi , During this time, I upgraded my video editing device , from iMovie Upgrade to fcpx, It took me. 10 Hot pot 、100 Spicy hot money , Think about how inexplicable a little distressed ..
I want to improve the quality of my videos , The most important thing is to add subtitles to the video , But I got stuck doing subtitles , Import fcpxml The subtitle file does not match the video time

Next, I will show you the steps of making subtitles , And show me the problem and my solution

First, only the voice of the video is exported mp3 file , Note that the exported voice file should not have background music

Then import this file into Netease external worktable In this website , After adjusting the error , We can get one srt Subtitle files

Then use the website to srt Document conversion fcpxml file , Import to fcp Inside , All the way up to this point, everything went well

But behind , When I paste subtitles into the project , I found that these subtitles are not aligned , Each subtitle seems to be a little longer

And when switching subtitles , There is overlap

And it is the kind that can be right at the beginning , The later the time error is, the greater , If they're not right , I can also drag the subtitles , Now I need to correct the time one by one , It's too troublesome

however , We programmers are not vegetarian , The problem of batch processing can be solved by code ~~

So I opened it fcpxml Subtitle files , Analyzed his source code , Sure enough, I found a solution !

I won't talk about the specific analysis process , I spent a day and a half analyzing it .. Tell us the reason why the time is not right

It is in the subtitle we exported , The end and the beginning are at the same time , So in the video , At the same time , There will be two subtitle frames

In this way, the length of each caption is increased by one frame , And then the error becomes larger and larger

We need to shorten the time of each letter by one frame , So the subtitles are correct , Will be fcpxml In the document duration Subtract the number after the field 100, such as

// The original 
 duration="2700/3000s"
// After modification 
 duration="2600/3000s"

If you are not a programmer , You can paste my code directly , No other software needs to be installed , Just follow me step by step

Let's start with this fcpxml Copy the subtitle file , Rename it to new file , And rename the original subtitle file to old

Come and get it old The path to this file , Right click on the file , Click to display the profile , This location is the path , Let's make a copy of

Go to the application and open the terminal , Paste path , The paste may be different from the display , Turn into English format , It's like this , The users here will become User

Next we use Ruby Language to solve , It will be automatically installed on Macintosh ruby Environmental , If you are not sure if there is such an environment , You can enter ruby -v Check the ,-v There is a space before it , If the version number appears , It means there are ruby Environmental Science , You can follow me in the following operations

~$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]

If not , You can find your programmer friends , Give him the code I'll paste next , Help you change it ~~

Of course, don't forget to send a red envelope to others , After all, programmers are very busy ~~~

We input... At the terminal irb, The front will become a serial number plus a rightwards arrow , Now you are in the state of code editing

~$ irb
2.2.1 :001 >

Next, let's define a path , Replace this path with the one you just copied old.fcpxml Path to file

~$ path = "/Users/xuzhaoning/Downloads"

Next, copy the following code

# Code copied for the first time 
text = File.read("#{path}/old.fcpxml")
f = File.open("#{path}/old.fcpxml", "r")
f.each_line do |line|
  m_duration = line.match(/duration.{
    2}(\d*)\/3000s.{
    1}/)
  if m_duration && m_duration[1]
  	m_duration_num = m_duration[1].to_i
  	if m_duration_num > 100
  	m_duration_num = m_duration_num - 100
  	end
  	m_duration_true = m_duration[0].gsub(m_duration[1],m_duration_num.to_s)
    puts "===m_duration=========#{m_duration[0]}======"
  	puts "===m_duration_true=========#{m_duration_true}======"
  	text = text.gsub(m_duration[0],m_duration_true)
  end
end

Will print out some information ,m_duration_true The last number is always better than the last line m_duration The following numbers are small 100, It means that the code runs successfully

Next we will copy the following code , Import the corrected subtitles into new.fcpxml In file

# A second copy 
path2 = "#{path}/new.fcpxml"
file = File.open(path2,"w")
file.write(text)
file.close

After completion of operation , Let's take this new.fcpxml File import to fcp in , Now the subtitle is consistent with the time of the video .

If there are few subtitles , It can also be in fcpxml Manual modification in the file duration The numerical , It should be noted that , This value can only be 100 Multiple , It can't be 50 55 Numbers like this

We have solved the problem of subtitles , So learn to write code , Not only can it be used to write projects , It can also solve many daily problems , come on. ~~

原网站

版权声明
本文为[Maoningyi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200552071250.html

随机推荐