Add keyframes to audio only flv files using flvtool2 [ windows ]
so i converted the mp3 file to flv using ffmpeg tool and then used the flvtool2 to add keyframe to flv file flvtool2 only adds key frames to flv files which have video stream in it does not add keyframes to audio stream
now there are two solutions
a – Add a video track to flv file and then process with flvtool2 it will add keyframes
b – Patch flvtool2 to support audio only keyframes
we will talk here about option # b
- Install ruby from here : http://rubyforge.org/projects/rubyinstaller/ – get oneclick installer
- now download ruby source http://svn.inlet-media.de/svn/flvtool2 , use svn tool like [ http://tortoisesvn.net/downloads ]
- browse to flvtool2 source directory and then to trunk folder and double click on setup.rb
- next apply the patch to files use the svn client to apply the patch / diff
Index: trunk/lib/flv/stream.rb
===================================================================
— trunk/lib/flv/stream.rb (revision 67)
+++ trunk/lib/flv/stream.rb (working copy)
@@ -43,6 +43,7 @@
:type_flags_audio,
:type_flags_video,
:tags,
+ :audio_keyframe_mode,
:stream_logdef initialize(in_stream, out_stream = nil, stream_log = false)
@@ -69,6 +70,7 @@
@extra_data = ”
@tags = []
end
+ @audio_keyframe_mode = false
end@@ -203,9 +205,20 @@
enddef keyframe_video_tags
+ @keyframe_video_tags_cache ||= keyframe_audio_tags if @audio_keyframe_mode
@keyframe_video_tags_cache ||= @tags.find_all do |tag|
tag.kind_of?(FLVVideoTag) && tag.frame_type == FLVVideoTag::KEYFRAME
end
+ end
+ def keyframe_audio_tags
+ result = nil
+ if !has_video? && has_audio?
+ result = []
+ src = audio_tags
+ # Get each 28 audio tag (~0.5 sec)
+ (0 .. src.size – 1).step(28) {|i| result << src[i] }
+ end
+ result
enddef audio_tags
@@ -286,7 +299,8 @@
enddef lastkeyframetimestamp
– return nil unless has_video?
+ return nil if keyframe_video_tags.nil?
+ #return nil unless has_video?
(keyframe_video_tags.last.nil? || keyframe_video_tags.last.timestamp.nil?) ? 0 : keyframe_video_tags.last.timestamp / 1000.0
endIndex: trunk/lib/flvtool2.rb
===================================================================
— trunk/lib/flvtool2.rb (revision 67)
+++ trunk/lib/flvtool2.rb (working copy)
@@ -29,7 +29,8 @@
module FLVTool2SHELL_COMMAND_NAME = (RUBY_PLATFORM =~ /win32/) ? ‘flvtool2.exe’ : ‘flvtool2’
– SWITCHES = %w{ s v r p x c i o k t n l a }
+ SWITCHES = %w{ s v r p x c i o k t n l a y }
+ #SWITCHES = %w{ s v r p x c i o k t n l a }
COMMANDS = %w{ U C P D A V }def self.parse_arguments
@@ -50,6 +51,7 @@
options[:in_point] = nil
options[:out_point] = nil
options[:keyframe_mode] = false
+ options[:audio_keyframe_mode] = false
options[:tag_file] = nil
options[:tag_number] = nil
options[:stream_log] = false
@@ -84,6 +86,8 @@
options[:out_point] = ARGV.shift.to_i
when ‘k’
options[:keyframe_mode] = true
+ when ‘y’
+ options[:audio_keyframe_mode] = true
when ‘t’
options[:tag_file] = ARGV.shift
when ‘n’
@@ -214,6 +218,7 @@
puts ” -t path Tagfile (MetaTags written in XML)\n”
puts ” -v Verbose mode\n”
puts ” -x XML mode instead of YAML mode\n”
+ puts ” -y Try to generate keyframes for audio only files automaticaly\n”
puts “\n”
puts “REPORT BUGS at http://projects.inlet-media.de/flvtool2”
puts “Powered by Riva VX, http://rivavx.com\n”
Index: trunk/lib/flvtool2/base.rb
===================================================================
— trunk/lib/flvtool2/base.rb (revision 67)
+++ trunk/lib/flvtool2/base.rb (working copy)
@@ -42,6 +42,7 @@
endprocess_files(options) do |stream, in_path, out_path|
+ stream.audio_keyframe_mode = options[:audio_keyframe_mode]
write_stream = false
options[:commands].each do |command|
write_stream = true if send( command, options, stream, in_path, out_path )save the above text as flvtool2_audio.diff in trunk folder and then apply the patch , the patch may not work if the source is updated or a new version of flvtool2 is released, in this case you will have to apply the patch manually
- now open command prompt and type
exerb "path\to\recipefile\flvtool2.exy"
flvtool2.exy will be already in the trunk directory , if the above command fails it means you do not have exerb go here [ http://exerb.sourceforge.jp/index.en.html ]
- Now you will have flvtool2.exe now to add keyframes to audio files use commandflvtool2 -U -y “filepath.flv”yes -y option add key frames to audio files, key frames will be added after each 0.5 sec
Download
Download Flvtool2 revision 67 source with patch applied : flvtool2 Revision 67
Patch file : flvtool2_Audio_Patch
Recent Comments