PDA

View Full Version : BMP files and compressing


koliva
17th February 2009, 17:32
Hello everyone,

I have a movie but every frames of the movie is saved as .bmp file. I have 800 frames consecutively. I would want to compress these .bmp files using H.264 coding. I would want to do it using c++ or c#. is there any sample code or could you please guide me?

thanks.:thanks:

lexor
17th February 2009, 17:41
Do you need it to be C/C#? How about, imagesource in avisyth to serve to x264, like any other movie?

koliva
17th February 2009, 17:48
Do you need it to be C/C#? How about, imagesource in avisyth to serve to x264, like any other movie?

I am generating these .bmp files myself. At the end of the process I have 800 .bmp files(frames). Therefore I need to combine them and compress them using H.264. I have heard JM software. Is x264 better than JM? By the way, I am newbie in this area :eek: I don't know what the avisyth is.

poisondeathray
17th February 2009, 18:07
Not to discourage you from learning about avisynth, but the learning curve is pretty steep....you can learn more about it here: http://avisynth.org/mediawiki/Main_Page

If you are new to this area, an easy option is to use avidemux which will automatically append your .bmp files if they are sequentially numbered (.eg. 001.bmp, 002.bmp, etc....) .

You can then use x264 in avidemux to encode a video (or other options like xvid, mpeg2 etc....)

koliva
17th February 2009, 18:15
thank you for all replies. I understand that this is very wide topic and I should read a lot of text about it. Let's start.

lexor
17th February 2009, 19:18
It's still not too hard. You don't actually need to interface with avisynth directly. Just create an avs file (essentially a text file) with imagesource and pass it to x264, just like you would if you were using x264 from a command line.


# Avisynth ImageSource sample:
# Read files "100.jpeg" through "199.jpeg" into an NTSC clip
ImageSource("%d.jpeg", 100, 199, 29.97)
You just use that line, and make sure you name your BMPs to play nice. Then just do process.start(PathTox264, args) and you are set. (plus error checking, and all that, of course).

Sagekilla
17th February 2009, 19:28
Try this:

ImageSource("Frame_%3d.bmp", start=0, end=800)

If your frames follow the format "Frame_001.bmp", "Frame_002.bmp", .... "Frame_799.bmp", "Frame_800.bmp", then you can use that. Otherwise, adjust accordingly If it's Image_xxx, use Image_%3d.

Sagekilla
17th February 2009, 19:33
Try this:

ImageSource("Frame_%3d.bmp", start=0, end=800)

If your frames follow the format "Frame_001.bmp", "Frame_002.bmp", .... "Frame_799.bmp", "Frame_800.bmp", then you can use that. Otherwise, adjust accordingly If it's Image_xxx, use Image_%3d.

koliva
20th February 2009, 10:36
I have a small problem,

Here is my .avs file


# Avisynth ImageSource sample:
# Read files "0_5_0.bmp" through "0_5_40.bmp" into an NTSC clip
ImageSource("0_5_%d.bmp", 0, 40, 29.97)


My files are 0_5_0.bmp, 0_5_1.bmp, 0_5_2.bmp, 0_5_3.bmp... 0_5_40.bmp

Then I opened VirtualDub and called my avs file. Here is error,

Avisynth open failure:
ImageReader: error 'illegal file header' in DevIL Library reading file c:\data\0_5_0.bmp
(c:\data\input.avs)

It seems that I can successfully get my images but it can't open them because of header or something else.

I searched on google but I could not find anything. Could you please help me?:thanks:

hanfrunz
20th February 2009, 15:08
can you post one example bmp-file?

koliva
20th February 2009, 15:15
can you post one example bmp-file?

Of course I can.

Here is the link Click (http://users.elis.ugent.be/~aavci/ppp/0_5_0.rar)

koliva
20th February 2009, 22:39
Of course I can.

Here is the link Click (http://users.elis.ugent.be/~aavci/ppp/0_5_0.rar)

I haven't still found a solution. I need help:helpful:

smok3
20th February 2009, 22:45
try with coronasequence (thats a plugin), this example opens your bmp fine:

coronaSequence("0*.bmp", sort=1)

not to mention you can skip the nasty regex filtering...

http://forum.doom9.org/showthread.php?t=109997

(i'am using this constantly for my png renders)

koliva
21st February 2009, 16:58
:(try with coronasequence (thats a plugin), this example opens your bmp fine:

coronaSequence("0*.bmp", sort=1)

not to mention you can skip the nasty regex filtering...

http://forum.doom9.org/showthread.php?t=109997

(i'am using this constantly for my png renders)


Thank you for your answer but I still have a problem. I know this is totally because of me but I need help :confused:

I changed my code like that,


LoadPlugin("corona.dll")
coronaSequence("0_5_*.bmp", sort=1)


I am using VirtualDubMod 1.5.10.2 version and it gives this error:


Avisynth open failure:
Plugin corona.dll is not an AviSynth 2.5 plugin
(C:\data\input.avs, line 3)


I am of the opinnion that I am doing something wrong or incomplete. Could you please help me again

Guest
21st February 2009, 17:06
Don't load that old corona.dll plugin.

Get ImageSequence from here:

http://avisynth.org/warpenterprises/index.html

It contains the function CoronaSequence().

koliva
21st February 2009, 20:51
Don't load that old corona.dll plugin.

Get ImageSequence from here:

http://avisynth.org/warpenterprises/index.html

It contains the function CoronaSequence().

Everything is quite ok so far. I have just installed ffdshow(for H.264 codec) and I can use it for encoding my video. My new question is;

In my avs script,

coronaSequence("0_5_%d.bmp", sort=1)

I also tried

coronaSequence("0_5_%d.bmp", start=0, stop=19,sort=1)


In this script, counter is not going one by one, instead of this, it goes how they are listed in the directory. As a result, my sequence order should be 0_5_0.bmp, 0_5_1.bmp, 0_5_2.bmp, 0_5_3.bmp, ... , 0_5_19.bmp(from 0 to 20). But now, it is something like that. 0_5_0.bmp, 0_5_1.bmp, 0_5_3.bmp, 0_5_2.bmp, 0_5_4.bmp, 0_5_5.bmp, 0_5_6.bmp, 0_5_7.bmp, 0_5_15.bmp, 0_5_8.bmp... I made these order up but nearly the same. How can I fix it?

zee944
21st February 2009, 21:34
If the numbers in your filenames would have the same number of digits, such as ...000, ...001, ....002 etc. then you could simply open it in VirtualDub. VirtualDub would auto-load the remaining pictures in order.

(Perhaps you have to use 'Append...' in file menu, but I'm sure VirtualDub can do it. Of course it'll be more useful in the future if you'd do it in AviSynth.)

koliva
21st February 2009, 21:40
If the numbers in your filenames would have the same number of digits, such as ...000, ...001, ....002 etc. then you could simply open it in VirtualDub. VirtualDub would auto-load the remaining pictures in order.

(Perhaps you have to use 'Append...' in file menu, but I'm sure VirtualDub can do it. Of course it'll be more useful in the future if you'd do it in AviSynth.)

Thank you for your answer. As you said in your post, I need to use avs script for my future codes. I need to fix this problem somehow.

kemuri-_9
21st February 2009, 22:05
since the OP was having some problems with this, thought i would try for a little bit with the one image that was provided (0_5_0.bmp)...

both

ImageReader("0_5_%d.bmp", start=0, end=0)
#still works w/ use_devil=true and use_devil=false as well

and

LoadPlugin("ImageSequence.dll")
CoronaSequence("0_5_%d.bmp",start=0,stop=0)


are working fine here...
there may be a problem with some of the other pictures,
so if they could be provided as well, could provide better assistance.

koliva
21st February 2009, 23:39
since the OP was having some problems with this, thought i would try for a little bit with the one image that was provided (0_5_0.bmp)...

both

ImageReader("0_5_%d.bmp", start=0, end=0)
#still works w/ use_devil=true and use_devil=false as well

and

LoadPlugin("ImageSequence.dll")
CoronaSequence("0_5_%d.bmp",start=0,stop=0)


are working fine here...
there may be a problem with some of the other pictures,
so if they could be provided as well, could provide better assistance.

I deleted "sort=1" code part and now it works well. This is enough for today. I need to sleep little bit. I can't learn everything within a day. :thanks::goodpost:

koliva
25th February 2009, 10:39
If I code

coronaSequence("0_5_%d.bmp", start=0, stop=80)


everything is ok. However, if I code

coronaSequence("0_5_%d.bmp", start=80, stop=0)

it doesn't work. How can I do it? Are there any help file for all these avs codes? I dont know what might be other parameters for coronaSequence. Where can I find them?

kypec
25th February 2009, 11:15
Are there any help file for all these avs codes? I dont know what might be other parameters for coronaSequence. Where can I find them?
In the ZIP package you downloaded from plugin's website is usually included HTML help file. Read it!

Gavino
25th February 2009, 12:23
However, if I code
coronaSequence("0_5_%d.bmp", start=80, stop=0)
it doesn't work.
If you want to show the images in reverse order, you can use Avisynth's Reverse (http://avisynth.org/mediawiki/Reverse)filter.
coronaSequence("0_5_%d.bmp", start=0, stop=80).Reverse()

koliva
25th February 2009, 13:33
LoadPlugin("ImageSequence.dll")
coronaSequence("0_5_%d.bmp", start=0, stop=80)
coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()


It shows only "coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()" sequence. I want to show "coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()" after "coronaSequence("0_5_%d.bmp", start=0, stop=80)". Not only second one. How can I do it? Is there any append method?

Gavino
25th February 2009, 14:15
coronaSequence("0_5_%d.bmp", start=0, stop=80)
\ + coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()
or perhaps easier to understand, and extensible in an obvious way:
part1 = coronaSequence("0_5_%d.bmp", start=0, stop=80)
part2 = coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()
part1 + part2
See the Avisynth wiki (http://avisynth.org/mediawiki/Main_Page)for information on basic scripting.

koliva
25th February 2009, 14:30
coronaSequence("0_5_%d.bmp", start=0, stop=80)
\ + coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()
or perhaps easier to understand, and extensible in an obvious way:
part1 = coronaSequence("0_5_%d.bmp", start=0, stop=80)
part2 = coronaSequence("0_6_%d.bmp", start=0, stop=80).Reverse()
part1 + part2
See the Avisynth wiki (http://avisynth.org/mediawiki/Main_Page)for information on basic scripting.


You are great!!! :rolleyes:

Please dont get bored with my stupid questions.

:thanks:

koliva
25th February 2009, 15:15
:(:(
Here is my next problem,

I tried to add ForNext block. Just to try if it works or not.

block = ForNext(50, 52, 1, """
coronaSequence("0_5_%d.bmp", start=${i}, stop=80)
""")
void = Eval(block)

It gives error like that:


Avisyneth open failure:
Script error: there is no function named "ForNext"


What is the problem now:(

Gavino
25th February 2009, 16:34
I assume you are trying to use the ForNext function outlined here (http://avisynth.org/mediawiki/Block_statements#The_for..next_block_statement).
(It appears you have jumped straight from the simple stuff to the more complex bits. :))

Unfortunately, this is just a 'proof-of-concept' - the page is incomplete as the function as such does not exist. This section is really just exploring how such a function could potentially be implemented in the scripting language.

The more usual way to do repetitive actions is via a recursive function (http://avisynth.org/mediawiki/User_defined_script_functions).

koliva
25th February 2009, 17:18
I assume you are trying to use the ForNext function outlined here (http://avisynth.org/mediawiki/Block_statements#The_for..next_block_statement).
(It appears you have jumped straight from the simple stuff to the more complex bits. :))

Unfortunately, this is just a 'proof-of-concept' - the page is incomplete as the function as such does not exist. This section is really just exploring how such a function could potentially be implemented in the scripting language.

The more usual way to do repetitive actions is via a recursive function (http://avisynth.org/mediawiki/User_defined_script_functions).


It would be perfect if there is a code like that


coronaSequence("0_%d_%d.bmp", start=0, stop=80, start=80 ,stop=0)


First one should start from 0 to 80, but seconc one should start from 80 to 0. I would want to use ForNext just because of this. Do you think that recursive function is the only way that I can do for this purpose?

Gavino
25th February 2009, 17:43
Recursion isn't needed for your case as you have exactly two sequences that can be written explicitly. For, example write a function like:
function corona2(string seq1, string seq2, int start1, int stop1, int "start2", int "stop2") {
start2 = default(start2, stop1)
stop2 = default(stop2, start1)
coronaSequence(seq1, start=start1, stop=stop1) + \
coronaSequence(seq2, start=stop2, stop=start2).Reverse()
}
Then your previous example could be achieved with:
corona2("0_5_%d.bmp", "0_6_%d.bmp", 0, 80)

With more work, the decision to use the reverse order for the second sequence could be made by comparing the start and stop numbers.

If you wanted to extend it to a variable number of sequences, then it gets more complicated, and a recursive function would be useful.

koliva
25th February 2009, 18:27
Recursion isn't needed for your case as you have exactly two sequences that can be written explicitly. For, example write a function like:
function corona2(string seq1, string seq2, int start1, int stop1, int "start2", int "stop2") {
start2 = default(start2, stop1)
stop2 = default(stop2, start1)
coronaSequence(seq1, start=start1, stop=stop1) + \
coronaSequence(seq2, start=stop2, stop=start2).Reverse()
}
Then your previous example could be achieved with:
corona2("0_5_%d.bmp", "0_6_%d.bmp", 0, 80)

With more work, the decision to use the reverse order for the second sequence could be made by comparing the start and stop numbers.

If you wanted to extend it to a variable number of sequences, then it gets more complicated, and a recursive function would be useful.

Your code is quite ok but I have 80 of them. So it means I have to do it 80 times one after each other. I think I have to use recursive one.

Gavino
25th February 2009, 20:16
Your code is quite ok but I have 80 of them. So it means I have to do it 80 times one after each other. I think I have to use recursive one.
Do you mean 80 different sequences of frames?
Can't you reduce them to a single sequence (or at least a smaller number) by suitable renaming of the files?

What is the existing naming scheme and what would your ideal scripting solution look like when applied to this? (ie what would you like to be able to write?)

koliva
25th February 2009, 20:28
Do you mean 80 different sequences of frames?
Can't you reduce them to a single sequence (or at least a smaller number) by suitable renaming of the files?

What is the existing naming scheme and what would your ideal scripting solution look like when applied to this? (ie what would you like to be able to write?)

I can write C code for that.


for(int i=0;i<80;i++)
for(int j=5;j<25;j++)
movie+= coronaSequence("0_%d_%d.bmp", &i, &j);


This is exactly what I am trying to do. I hope that you have understood me.

Gavino
25th February 2009, 22:23
I can write C code for that.

for(int i=0;i<80;i++)
for(int j=5;j<25;j++)
movie+= coronaSequence("0_%d_%d.bmp", &i, &j);

This is exactly what I am trying to do. I hope that you have understood me.
If I understand properly, something like this ought to work:
function MultiSeq(int i) {
seq = CoronaSequence("0_"+string(i)+"_%d.bmp", 5, 24)
i == 0 ? seq : MultiSeq(i-1) + seq
}

which you would then call as
MultiSeq(79)
Even if I've got the details wrong, hopefully you will understand the general approach.