View Full Version : FFmpegSource
Myrsloik
5th October 2008, 16:44
The indexing program wasn't written by me and I actually haven't looked closely at the source yet (but I suspect that I soon will have to). Most likely TheFluff did something very clever. So clever no other CLI app does it. In the future it should also be easier for you to link directly to ffms2.dll when doing indexing. (unless you use a very weird programming language)
1) They are identical to the four first of FFVideoSource. (source, track, cache, cachefile)
2) No, there's no reliable way that I know of to skip frames in the way that's required. All I can think of would more or less be equivalent to putting trim() after the source filter.
3) I think all of those are directed to stderr but I'm not sure. Logging things seems to be very integrated into ffmpeg itself so I'm not sure what can be done about it but I'll look into it.
Atak_Snajpera
5th October 2008, 20:50
I have a problem with the ffmsindex.exe program. I want to use it because unlike FFVideoSource it can show it's process. Unfortunately once I use it from my program it doesn't show the progress anymore.
I have the same problem. It would be nice if you added switch so every percent would be in new line. This should solve our problem.
vlada
5th October 2008, 20:51
Atak_Snajpera> I'm glad you confirmed the problem. I was afraid there might be something wrong on my side.
Myrsloik> Thanks a lot for your answers. I know that the indexing program wasn't written by you, but I hope TheFluff is hanging somewhere around. I'm using Python as my programming language. There is a ctypes wrapper to load compiled C libraries. But I have no knowledge how to use it. Also I would have to introduce threading, because using external DLL locks the main loop. So an external CLI application (which runs in a separate process by default) is right now the best solution for me.
I'm working on a program which would take any input video, process it with AviSynth and output it to many predefined formats (based on presets). It should be able to process many files at once. The workflow is following:
1) You select your files to convert
2) The files are added to list and analyzed (audio/video parameters, autocrop etc.) and previews are created
3) You select a preset (PMP model, cellphone model, typical HD rip or custom preset)
4) Just press "Encode" and wait until it is finished.
There is an additional 2b step step, where you can change many parameters, but some are locked or limited to keep compatibility with the preset you selected. So using it should be really simple. But I'm currently not satisfied with the step 2. Opening video files takes a long time (mainly because of indexing) and I can't even show it's progress. Choose one file, wait a minute, then choose another one, another minute and so on. That disappoints you...
So this why I was asking if it would be possible to index only a part of a video file. To display a preview or to detect letterboxing I only need few frames from the video. As you said - like using Trim() - but much faster. The full indexing would be done before compression.
As for the errors, I get them from stdout. But maybe I've redirected the stderr to stdout. As I said I'm still quite lost in this, I only understand the high level programming. I will need to have a deeper look into this and how do the modules I use work. In case somebody's interested I use this (http://code.activestate.com/recipes/440554/) module to run external processes.
Quark.Fusion
11th October 2008, 16:00
Looks like there is memory leak during indexing of a file — during indexing of 50gb m2ts file memory usage pimp up to 1.6gb and ffmsindex crashed (same with virtualdub).
Is it ever possible to access file in linear manner without indexing?
Myrsloik
11th October 2008, 17:17
There shouldn't be any leaks in that part of the code, at least not that depend on the number of frames or file size. Did it get far before crashing? How far does it get in the the file if you use ffmsindex.exe?
I guess I could add yet another seekmode that does linear access without indexing. The problem is that you would have to specify exactly how many frames the source has since avisynth (and vfw in general) doesn't allow it to change after a file has been opened. Could it still be useful with that limitation?
Quark.Fusion
11th October 2008, 17:56
I don't sure at which frame it crashes, but there is definitely a memory leak as memory usage go up and up, with my file it crashes near 900MB of file position. Also during indexing it uses 100% of single core while reading file very slowly — is it decoding to build index?
Maybe it tries to allocate some buffer with size as fraction of system memory? My system is Vista x64 with 8GB RAM.
I can't understand why you can't detect number of frames as directshow returns it without indexing (or that estimated value?).
buzzqw
12th October 2008, 09:54
The problem is that you would have to specify exactly how many frames the source has since avisynth (and vfw in general) doesn't allow it to change after a file has been opened. Could it still be useful with that limitation?
not mutch, because we must rely on another tool for analyze the movie
BUT if easy to implement.. feel free to do it :) thanks
BHH
Quark.Fusion
12th October 2008, 12:27
not mutch, because we must rely on another tool for analyze the movie
It's still faster that waiting for index, especially when it can't construct it :)
liquidator87
12th October 2008, 14:08
I can confirm the huge memory usage during indexing... till the program crashes :(
Tried to index a 20 GiB m2ts file, the memory usage increases till it reaches the max... then BUM!
vlada
12th October 2008, 18:30
I guess I could add yet another seekmode that does linear access without indexing. The problem is that you would have to specify exactly how many frames the source has since avisynth (and vfw in general) doesn't allow it to change after a file has been opened. Could it still be useful with that limitation?
This would be very useful for me, because I detect the number of frames with MediaInfo anyway. So I know the number of frames before creating the AviSynth script.
saint-francis
21st October 2008, 14:43
Myrsloik, are you interested in samples that make you tool crash?
Myrsloik
21st October 2008, 15:32
Yes, if they don't also make fairly recent mplayer/ffmpeg compiles crash. Or have been mentioned in the two previous pages because I can still remember those.
Akatsuker
28th October 2008, 12:10
Hi, i've just tried the FFVideoSource in a VFR mkv file. All the time, all that I've got is:
"Could not open video codec"
FFVideoSource("E:\video02.mkv",timecodes="TESTTIMECODES.tc",seekmode=1)
I don't know, maybe I doing this wrong. Can you help me?
Thanks a lot in advance.
loliconxd
28th October 2008, 12:47
mmmm, ffmpegsource can't open correctly vfr files, try with dss or dss2.
tacman1123
20th November 2008, 19:02
I have the FFMS2.dll in my plugins directory, but I still get an error using FFMegSource() -- did the call change as well? I had another problem, I think, with FFMegSource.dll in the directory as well, is that Version 1?
EDIT: I figured it out, at least I think I did, the call is now FFMS2_FFVideoSource(), yes?
LoRd_MuldeR
20th November 2008, 19:03
There is no FFMpegSource() in FFMS2.dll (version 2), you must use FFVideoSource() and FFAudioSource() now. Also FFMegSource.dll (version 1) won't be needed!
Didn't you read the readme file? ;)
Myrsloik
20th November 2008, 20:56
A possibly fixed version of the cli index app is now available from http://ivtc.org/new/beta/ffmsindex-progressfix.7z
Try it and report the results. Don't expect any major updates until 2011.
Fizick
20th November 2008, 21:39
Thanks, 2011 is not so distant year :)
tacman1123
20th November 2008, 23:39
I don't have FFDSHow or Haali Splitter installed, they seemed to really interfere with basic playing of AVI files and returning bad frame info when those avi files were called through Avisynth.
So I was hoping that my mp4 file, which definitely has audio in it and plays fine in GOM, would be able to get the audio with FFVideoSource and/or FFAudioSource. FFVideoSource returns HasAudio as false, and when I try to load the mp4 file with FFAudioSource(mp4_filename), it gives me
Evaluate: System Exception - Access Violation
Any chance I'll be able to hear audio of mp4 files through avisynth with FFAudioSource? Or something else?
Thx,
Tac
LoRd_MuldeR
20th November 2008, 23:45
You need to do it like that:
v = FFVideoSource("C:\Foobar.mp4")
a = FFAudioSource("C:\Foobar.mp4")
AudioDub(v,a)
But if FFAudioSource() fails on your source file, you'll need to obtain the audio in a different way...
vlada
2nd December 2008, 10:06
A possibly fixed version of the cli index app is now available from http://ivtc.org/new/beta/ffmsindex-progressfix.7z
Try it and report the results.
Thanks for the updated version. Unfortunately it still doesn't work for me unless I'm doing something wrong. The CLI output is still a single line. I get no output during indexing, after it finishes, I get 33% and 67% progress messages. Any idea what might be wrong?
CruNcher
2nd December 2008, 15:43
@Myrsloik
Any progress on the GPU Decoding support ?
Myrsloik
2nd December 2008, 17:55
When I say 2011 I MEAN 2011. If anyone in Sweden wants to buy a new very lightly used GF8400 GS send me a message. The only thing I've worked on is the other link and there's a serious bug somewhere in that project. But look forward to 2011, it will be a year to remember.
vlada
29th December 2008, 01:33
During the Christmas I spent quite a lot of time on finishing my transcoding application. I discovered some bugs and problems in FFmpegSource which I would like to report.
1) The first and most serious bug is related to index reading and creating. I found out that files with accented character in path can't be opened. There is a problem with codepage conversion somewhere. Let's say my file is C:\ěščřž\video.avi. Simply using FFVideoSource would fail. But if I specify the location of index to C:\temp\index.tmp, then it opens. The standalone FFMSIndex has the same problem. I use cp1250 for AviSynth script encoding.
2) Another problem is that some errors and warnings are probably output to STDOUT and then it is sent to encoders STDIN and the output is corrupted. It might be a mistake on my side too, because it only happens if I run it from my program. If I run the same command separately the created video is correct, but the encoder's output is mixed with error/warning messages from FFmpegSource. Would it be possible to disable all such messages, maybe by an option/switch?
3) Then I found some FLV (VP6F/MP3) files, which produce a silent audio track. The files work correctly in ffmpeg.
If you are interested into samples showing the #3 issue, let me know. If you need any further details to the first 2 problems, I can provide that too.
Thanks a lot for looking into these problems. I can't release my program without having a fix or workaround for the first 2 points.
Myrsloik
29th December 2008, 17:00
1. Does it work with avisource or directshowsource or any other source?
2. Call FFNoLog() first in the script in the next version
3. It's always good to have more test clips
Could you also make a small program that shows your problem with the indexing app? that way it's much easier to get TheFluff to fix it.
If you want to test what will be the next version find me in #darkhold on rizon and I'll send it to you (or anyone else who wants to test stuff).
Myrsloik
31st December 2008, 01:22
New beta released, mostly because FFmpeg was getting a bit old. The big news is greatly improved and slightly broken TS parsing. It now uses Haali's splitter (needs to be installed or TS files won't work) to provide almost frame accurate seeking. Almost meaning that if you access the first 200 frames or so it won't work right but if you only access later frames it has in my testing always worked perfectly. (yes, very weird)
So if you use it you might want to do something like
FFVideoSource(...).Trim(200,0)
for now.
SAPikachu
31st December 2008, 06:40
Hi,
First of all, thanks for your great filter, it helped me a lot.
I'm using FFMpegSource in my program, it can get key frame list from index file and seek by key frames. With beta 3, seeking to a key frame is very fast. But it is significantly slower in beta 4. For mp4 container, it is ~5x slower with beta4 than with beta3. MKV is faster than mp4, but still slower than with beta3.
Could you look into this problem? If you need some video samples, please let me know. Thanks in advance.
Myrsloik
31st December 2008, 14:48
I forgot some debug code when seeking that made it decode many more frames. Redownload beta 4 and it will be fixed.
SAPikachu
1st January 2009, 03:56
The problem is solved, thanks a lot!
vlada
2nd January 2009, 21:47
1. Does it work with avisource or directshowsource or any other source?
2. Call FFNoLog() first in the script in the next version
3. It's always good to have more test clips
Could you also make a small program that shows your problem with the indexing app? that way it's much easier to get TheFluff to fix it.
1) The problem is only in index location, not in the file location. So there are no problems with the file using AviSource or DirectShow source.
2) Thanks for the improvement!
3) For the not working Flash Video see this file (http://rapidshare.com/files/179397958/IK_-_WWW.flv.html) (4,5 MB).
As for my problems with getting progress from ffmsindex.exe, here is a sample code: http://rapidshare.com/files/179395825/test.zip.html (4 kB).
To run it you would need PyGTK (= Python, PyGTK, PyGobject, PyCairo), GTK+ and Python Win32 Extensions. All installers can be easily found and downloaded. If you (or TheFluff) prefer, I could provide a compiled version including all libraries, but this way you can look into the source code and modify it.
loliconxd
9th January 2009, 15:09
one question.
the ffmpeg.. 2.0 support vfr?
TheFluff
9th January 2009, 21:42
one question.
the ffmpeg.. 2.0 support vfr?
What do you mean by "support"? It can read timecodes from the loaded file and write them to a timecodes file, but since Avisynth doesn't support VFR, it will set the framerate to some arbitrarily chosen bogus value (for mkv's it's based on the average frame duration, for everything else it's based on the duration of the first frame) and let you decide what you want to do with it. If you mean convert VFR to CFR, that is supported too, just read the manual.
vlada: I will look at your problem sometime after next weekend.
guest0815
16th January 2009, 14:10
Where did the timecodes' decimal places go with ffmpeg2?
#timecode format v2
0.000000
41.708333
83.416667
...
#timecode format v1
Assume 23.976000
#timecode format v2
0
41
83
...
#timecode format v1
Assume 23.976000
0,0,24.390244
1,2,23.809524
3,3,24.390244
4,5,23.809524
...
thank you
Myrsloik
19th January 2009, 00:38
They will return in the next version. (if I remember to fix it)
TheFluff
24th January 2009, 17:39
@vlada: I've been looking at your problem with ffmsindex.exe and can't reproduce it with any code I've written myself. For example, this perl script:
#!/usr/bin/perl
my $res = `ffmsindex -f "blah.mkv"`;
$res =~ s/\r/\r\n/g;
print $res;
prints this, as expected:
Indexing, please wait... 0%
Indexing, please wait... 1%
Indexing, please wait... 2%
Indexing, please wait... 3%
Indexing, please wait... 4%
Indexing, please wait... 5%
Indexing, please wait... 6%
Indexing, please wait... 7%
(etcetera)
Indexing, please wait... 100%
Writing index... done.
I can't see how this is a problem on my side. I'm doing things pretty much exactly like every other CLI app, including x264, except I'm using the C++ iostream instead of x264's plain c stdio. I don't know what you're doing wrong but it's probably something trivial (such as forgetting to convert \r to \r\n or something).
MadRat
25th January 2009, 21:57
Thanks for the update, I'm eager to use the release version.
lubczyk
30th January 2009, 06:58
So what do I use to convert from vfr to cfr in the syntax? Do I set one and or both fpsnum and/or fpsden and what values are expected? I know the framerate of my video BTW.
TheFluff
1st February 2009, 10:32
FFVideoSource(string source, int track, bool cache = true, string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1, string pp, int threads = -1, string timecodes, int seekmode = 1)
(...)
fpsnum & fpsden:
For VFR -> CFR conversion. Setting fpsnum <= 0 means a 1:1 relation with the encoded frames.
Other hints:
num stands for "numerator" and den stands for "denominator"; as in a fractional number.
Both parameters are integers.
fpsnum defaults to -1; fpsden defaults to 1.
Standard NTSC framerate is not 29.97fps, it's 30000/1001fps exactly.
If you are completely lost, check out the Avisynth documentation for AssumeFPS/ChangeFPS/ConvertFPS.
I'm sure you can figure it out from there.
lubczyk
3rd February 2009, 22:26
Other hints:
num stands for "numerator" and den stands for "denominator"; as in a fractional number.
Both parameters are integers.
fpsnum defaults to -1; fpsden defaults to 1.
Standard NTSC framerate is not 29.97fps, it's 30000/1001fps exactly.
If you are completely lost, check out the Avisynth documentation for AssumeFPS/ChangeFPS/ConvertFPS.
I'm sure you can figure it out from there.
Thank you!!! That helped alot.
lubczyk
4th February 2009, 16:01
Any plans for subtitle support? It would be great if FFmpegSource eventually evolved into a total DirectShowSource (Video, Audio, Subtitles) replacement.
Myrsloik
4th February 2009, 18:56
No, never.
1. There is no support for it in avisynth, I really would like to be able to return multiple clips (arrays?) from a filter but you can't. There's also no decent way to pass subtitle data around apart from storing it in a clip (which will fail in the same way as directshow, skip beyond a subtitle starting point and you won't know it should appear).
2. There is only ONE good renderer. VSFilter. I would not try to reimplement this thing even if you paid me millions.
3. Directshow exists.
4. Why would I ever try to replace directshow with something as limited as avisynth? It makes no sense.
5. What's so difficult about using ffmpeg to demux the subtitles and then render then with VSFilter? Clever scripting and the "run exe files from avisynth" filter should be able to do it.
Mini trolling not appreciated. Do not bother to reply without good rebuttals to all points.
Sagekilla
5th February 2009, 02:46
Myrsloik, would it still be possible to return a clip with video + audio though?
I know you can do something like this, where you dub audio into the video:
v = Avisource("...")
a = Wavsource("...")
out = AudioDub(v,a)
But would it be possible to return video + audio as a single clip?
Myrsloik
5th February 2009, 08:08
Write a nice wrapper function, post it here (bonus points if you also write one for compatibility with v1). I don't see any reason because internally it would be identical to a simple avsi file with the function(s).
TheFluff
6th February 2009, 02:27
Write a nice wrapper function, post it here (bonus points if you also write one for compatibility with v1). I don't see any reason because internally it would be identical to a simple avsi file with the function(s).
function ffmpegsource2(string source, int "vtrack", int "atrack", bool "cache", \
string "cachefile", int "fpsnum", int "fpsden", string "pp", int "threads", \
string "timecodes", int "seekmode", bool "overwrite") {
vtrack = default(vtrack,-1)
atrack = default(atrack,-2)
cache = default(cache,true)
cachefile = default(cachefile,source+".ffindex")
fpsnum = default(fpsnum,-1)
fpsden = default(fpsden,1)
pp = default(pp,"")
threads = default(threads,-1)
timecodes = default(timecodes,"")
seekmode = default(seekmode,1)
overwrite = default(overwrite,false)
((cache == true) && (atrack <= -2)) ? ffindex(source=source, cachefile=cachefile, \
indexmask=0, overwrite=overwrite) : (cache == true) ? ffindex(source=source, \
cachefile=cachefile, indexmask=-1, overwrite=overwrite) : nop
v = ffvideosource(source=source, track=vtrack, cache=cache, cachefile=cachefile, \
fpsnum=fpsnum, fpsden=fpsden, pp=pp, threads=threads, timecodes=timecodes, \
seekmode=seekmode)
a = (atrack <= -2) ? blankclip(audio_rate=0) : ffaudiosource(source=source, \
track=atrack, cache=cache, cachefile=cachefile)
return audiodubex(v,a)
}
not very well tested
Parameters should be more or less self-explanatory (in most cases named identically to the ffms2 equivalents); overwrite controls whether the cachefile is overwritten or not if it already exists.
Almost completely backwards compatible with v1.
edit: dumb bug spotted, functionality commented out, watch this space for an edit
edit the second: dumb bug fixed. the fix made me realize that there is apparently no way to conditionally return from an avisynth function (the first version of this had something along the lines of "(atrack == -2) ? return v : nop" which of course didn't work because apparently return isn't a function).
edit the third: maybe I should just let atrack default to -2 like in ffms v1 and skip the try/catch block entirely.
edit the fourth: yeah that's a better idea
edit the fifth: fixed the last dumb bug, where overwrite=true wouldn't do anything if atrack==-2.
dansus
8th February 2009, 08:05
Hi, im try to open an H264 TS file with
FFVideoSource("D:\Enc\HD\hd.ts").Trim(200,0)
and i get;
Codec returned zero size video (source.avs line1)
I have a feeling im being stupid and missed something simple...
buzzqw
8th February 2009, 09:21
Have you try without trim ?
BHH
dansus
8th February 2009, 18:02
Yep.
Myrsloik said to you use Trim(200,0) or it wouldnt work. But not happy either way.
vlada
9th February 2009, 00:29
TheFluff>
I'm sorry for my very late feedback. Unfortunately I still can't get progress from ffmsindex.exe. I created a new extremely simple example which shows it. You only need Python (2.5 or 2.6) to try it. Please find the example here: http://www.sendspace.com/file/vq4rhc (if you prefer it uploaded somewhere else, please let me know).
The problem might be in the module (subprocess2.py) I use. It wasn't written by me, but it works perfectly with all other programs I tried (xvid_encraw, MPlayer, Mencoder, ffmpeg, MP4Box) on both Linux and Windows. Atak_Snajpera reported the same problem that I have.
Atak_Snajpera>
Does the ffmsindex.exe progress reporting work for you?
Myrsloik>
I have a file (*.m2v) which has a strange seeking problem with FFVideoSource(). I noticed that during my work on a script for automatic interlacing/telecine detection. As you can imagine, it is important to get the exact frames. But sometimes I get different frame then I want. For example if I seek to frame 100, I always get 101. Is this a known problem with elementary streams or are you interested in a test file?
Myrsloik
9th February 2009, 15:16
Hi, im try to open an H264 TS file with
FFVideoSource("D:\Enc\HD\hd.ts").Trim(200,0)
and i get;
Codec returned zero size video (source.avs line1)
I have a feeling im being stupid and missed something simple...
Cut off the first 10MB of the file or so and upload somewhere. That shouldn't happen. The Trim itself has nothing to do with video size.
TheFluff>
Myrsloik>
I have a file (*.m2v) which has a strange seeking problem with FFVideoSource(). I noticed that during my work on a script for automatic interlacing/telecine detection. As you can imagine, it is important to get the exact frames. But sometimes I get different frame then I want. For example if I seek to frame 100, I always get 101. Is this a known problem with elementary streams or are you interested in a test file?
I don't really support m2v files that much right now since dgindex usually works. There is a very similar issue for transport streams too. Upload a sample somewhere if you want me to look at it but as usual I'm insanely busy for at least another month so don't expect quick fixes.
I'll also try to find some ftp space for huge uploads soon so I don't have to deal with the useless free file hosts... Donations are very welcome.
ajp_anton
13th February 2009, 04:11
Sorry to "repeat" requests, but last time was half a year ago and you never said you won't do it... =)
Could you add a display for things like frame type, frame size (in bytes), and maybe other things that I don't need, like ffdshow's OSD?
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.