View Full Version : I'm trying to make a "C" script to play clips in random order.
Jeremy Duncan
23rd April 2011, 23:40
I want to take these clips, have clip one as the beginning and clip 27 as the ending, but the clips inbetween varied.
I want to vary the clips 2 to 26 so they play in a special random order.
That special random order is based on boolean true false statement, like this;
int main()
{ int one, two, three;
one=1;
two=2;
three=3;
if((two<=three)&&(three>=1));
play clip two;
else play clip 3;
variable name is one.
variable name value is 1.
How do I add the number of frames in the clip to variable name value?
The clips would have to have these numbers from the number of frames to make the clips have the values; greater than, equal to, or less than.
What gives the clips special values is total frame numbers in the clips, but I don't know how to add that to the variable name value.
So I want you to do two things for me:
1.) add frame number values to the variable name's number. Right now I have one=1, two=2, but it could be, one=("clip has this many frames:")
2.) make the clips play in the order I specified: one is the beginning of the video sequence, two is the last clip in the video sequence, join these beginning and ending clips is clips 2 to 26.
3.) Could you do write your answer in C not C++? I'm learning C and this would help me more than you can imagine.
Here is the source; link (http://www.mediafire.com/?95s27fp44vo2t2e), made up of clips one to 27. Put the clips folder in the C:\ folder.
And here is the start of the avs file I made so you only have to write the code instead of drafting this monotonous work.
loadplugin("C:\Program Files\AviSynth 2.5\plugins\DirectShowSource.dll")
one=directshowsource("C:\clips\1.mp4", audio=false, 23.976)
two=directshowsource("C:\clips\2.mp4", audio=false, 23.976)
three=directshowsource("C:\clips\3.mp4", audio=false, 23.976)
four=directshowsource("C:\clips\4.mp4", audio=false, 23.976)
five=directshowsource("C:\clips\5.mp4", audio=false, 23.976)
six=directshowsource("C:\clips\6.mp4", audio=false, 23.976)
seven=directshowsource("C:\clips\7.mp4", audio=false, 23.976)
eight=directshowsource("C:\clips\8.mp4", audio=false, 23.976)
nine=directshowsource("C:\clips\9.mp4", audio=false, 23.976)
ten=directshowsource("C:\clips\10.mp4", audio=false, 23.976)
eleven=directshowsource("C:\clips\11.mp4", audio=false, 23.976)
twelve=directshowsource("C:\clips\12.mp4", audio=false, 23.976)
thirteen=directshowsource("C:\clips\13.mp4", audio=false, 23.976)
fourteen=directshowsource("C:\clips\14.mp4", audio=false, 23.976)
fifteen=directshowsource("C:\clips\15.mp4", audio=false, 23.976)
sixteen=directshowsource("C:\clips\16.mp4", audio=false, 23.976)
seventeen=directshowsource("C:\clips\17.mp4", audio=false, 23.976)
eighteen=directshowsource("C:\clips\18.mp4", audio=false, 23.976)
nineteen=directshowsource("C:\clips\19.mp4", audio=false, 23.976)
twenty=directshowsource("C:\clips\20.mp4", audio=false, 23.976)
twenty_one=directshowsource("C:\clips\21.mp4", audio=false, 23.976)
twenty_two=directshowsource("C:\clips\22.mp4", audio=false, 23.976)
twenty_three=directshowsource("C:\clips\23.mp4", audio=false, 23.976)
twenty_four=directshowsource("C:\clips\24.mp4", audio=false, 23.976)
twenty_five=directshowsource("C:\clips\25.mp4", audio=false, 23.976)
twenty_six=directshowsource("C:\clips\26.mp4", audio=false, 23.976)
twenty_seven=directshowsource("C:\clips\27.mp4", audio=false, 23.976)
Jeremy Duncan
24th April 2011, 12:31
If you would rather make the code from edit one in the first post in C++, then please do so. All I need is for it to be a functional plugin.
I will get to C++ after I learn C.
Groucho2004
24th April 2011, 21:25
If you would rather make the code from edit one in the first post in C++, then please do so. All I need is for it to be a functional plugin.
Do you want fries with that?
Jeremy Duncan
25th April 2011, 01:15
Hi Groucho,
I didn't expect any help, but I thought what could it hurt to ask?
I'm reading the guide made by D graft on how to make a avisynth plugin. I'm going to read that once a day along with my C course and then try my hand at c++ and then trying to make that plugin.
Don't bother trying to help me if you don't want to, it's not that important - I'll do it.
Groucho2004
25th April 2011, 08:09
OK, I'll bite.
From what I understand, you want to play a directory with a bunch of clips in random order, right?
The pseudo code you posted does not make any sense:
That special random order is based on boolean true false statement, like this;
int main()
{ int one, two, three;
one=1;
two=2;
three=3;
if((two<=three)&&(three>=1));
play clip two;
else play clip 3;
The bold condition is always true because 2 is always < 3 and 3 is always > 1.
So, if you want help, we'll need to know what random order you want.
Adding the number of frames to the file name of a clip is quite simple, the easiest would probably be getting the number of frames through mediainfo and then renaming with some VB script (yuk).
Also, why do you have to involve Avisynth? Why not play the clips directly in your media player?
Jeremy Duncan
25th April 2011, 11:37
bad code removed
It looks like this, and then you just fill in enough if statments then add else statements so all 27 clips are used.
I added two if statments but I could have put twenty there or so.
It compiles in visual studio 2010 express, so the code is good.
And your statement: "2 is always < 3 and 3 is always > 1." is false because the variable name value is not set as equal to the name of the variable: two= (2>= 10) = true, possibly, if the number of frames in two is up to ten frames.
Why use avisynth instead of just making it like a youtube video? Because I envision a folder with different clips from different movies or shows from youtube, but all in the same folder, then the avisynth file goes to that folder and plays the clips based on the boolean values in the avisynth code.
It would look different every time I changed the clips in the folder.
I don't know the Exact boolean math oto use. I would have to get it running then test it to see the values tha give the most pleasing results when I watch the clip.
How are you going to help? Will you make this into a avsi? :thanks:
Gavino
25th April 2011, 12:01
It compiles in visual studio 2010 express, so the code is good.
Just because it compiles doesn't mean it does anything sensible, or even works at all.
For example:
/* initialize all the movies in the array */
for ( one = 1; one <= twenty_seven; ++one ) {
if((two<=three)&&(three>=1));
{
movies[three]=movies[two];
}
if((four<nine)&&(five>=1));
{
movies[nine]=movies[four];
}
The semicolons terminate the two 'if' statements, so they have an empty body and the following { .. } blocks are executed unconditionally. Further, you are using movies[two] and movies[four] before they have been initialised, producing garbage results.
I have no idea what you're trying to do and your code looks like complete nonsense to me.
The idea of "turning C code into an avsi" doesn't make much sense either.
Groucho2004
25th April 2011, 13:16
It compiles in visual studio 2010 express, so the code is good.
That's a keeper! I might put this in my signature with your permission.
Zarxrax
25th April 2011, 14:04
Unless there is a reason that it needs to be in C, this can be done quite easily with a macro for AvsP(mod).
I was actually already thinking about writing something for this purpose, as I needed a way to randomize clips as well.
I can look into it later today or later this week maybe, if that would be satisfactory.
LaTo
25th April 2011, 15:13
That's a keeper! I might put this in my signature with your permission.
Signed JD, as usual (http://forum.doom9.org/showthread.php?t=142706&page=2) :rolleyes:
Otherwise it might be better to read some books about C/C++ and some examples of avisynth's SDK before starting a plugin from scratch...
Jeremy Duncan
25th April 2011, 17:42
[CODEcode removed. new code with no colpiling errors posted below.[/CODE]
But otherwise, how does the code look so far? :)
Zarxrax
25th April 2011, 17:54
Heres the macro i made for avsp, if it might be of help.
http://www.mediafire.com/?4ifpdzcabzchyha
You select a directory containing all the files you want to add, and it will add them all to a new script in a random order
Jeremy Duncan
25th April 2011, 18:05
Hi Zarxrax,
I looked at your py file but it's not what I was looking for.
Actually if I can ask Gavino to look at the code I just posted with the compiling errors, and say if it's sound method just fix the errors, then may I ask you to put the code into a py file once the compiling errors are fixed? :)
That would be cool, then I could just add the clips from post one to a folder and open them with the py file and avsp mod. :)
Zarxrax
25th April 2011, 18:12
Well python is quite different from C, so I dunno.
Jeremy Duncan
25th April 2011, 18:33
This code has no compiling errors.
bad code removed
Zarxrax, maybe try to put this code into python code, and use the clips in the first post in avsp with the py file you make to see if our code works? :)
Zarxrax
25th April 2011, 18:49
Hmm... I dont really understand your code :p
Jeremy Duncan
25th April 2011, 21:01
Hmm... I dont really understand your code :p
What is it doing you mean?
The for loop is made up of:
variable name = int number
test step: variable name <= int value or name
increment step: variable name ++
I use my imagination to describe what this does:
The for loop is a circle that has a circumference, and this circumference is the (variable name=int number) step.
The test step is the centre of the circle.
The increment step is what joins the circumference with the centre of the circle.
This circle can be made up of a while loop too, like this:
variable name = int number, this is the circumference of the circle.
The test step which is variable name >= int number of variable name. This is the centre of the circle.
Increment step, or variable name ++
The centre is joined to the circumference by the increment step.
If there is a if statement within the while loop, this is put within the circle and if executed is equal to another point that the increment step joins to on it's way to the centre, inline with the center and circumference of the circle.
What my code does is it fills the circle from the circumference to the centre using the for loop.
The increment step goes from the first step which is on the circumference to the last step which is the centre of the circle.
What the increment step consists of is the variable names: one, two, etc.
The if statements go to a clip from the circumference to the centre, and they are only testing if the increment step they go to goes to is done in a random or linear order.
If it is done in a random order them it goes to clip two and equals clip one.
If it is done in a linear order it goes to clip two and stays at clip two.
http://thumbnails26.imagebam.com/12955/8e04f4129545060.jpg (http://www.imagebam.com/image/8e04f4129545060)
But, remember this is my imagination describing a language I don't really understand.
noee
25th April 2011, 21:07
I don't mean to troll and I mean this in a light-hearted way, but you have taken Rube Goldberg to the next level.
Instead of trying to abstract the code into some sort of description, why not just describe what you're trying to accomplish in simple language. Like:
"I want to loop thru a folder and create a random list of files from the folder and then play that list."
Jeremy Duncan
25th April 2011, 22:00
I'm going to join a video clip to each int variable. So int one is joined to video clip one. Joining the video clips is the "next" step, I'm not concerned with that right now.
Each video clip will have their own extra value of total number of frames, so "int one = video clip with x number of frames".
"Assuming" each int variable represents a video clip, I'm here to ask if the code works.
2 is always < 3 and 3 is always > 1. This means to be Random, I change this clip from; two equaling two, to two equalng one.
The list of for statements giving clips values is followed by a final for loop. This final for loop is supposed to play all the clips in the order they equal.
Zarxrax
25th April 2011, 22:09
Let's try this a different way.
Aside from whatever you are saying about the number of frames, what aspects of the previously posted python script dont meet your needs?
Groucho2004
25th April 2011, 22:20
Jeremy,
1. I still don't understand what you want to achieve (and I'm sure I'm not the only one).
2. The code you posted is, as noee aptly put it, equivalent to taking the Rube Goldberg machines to the next level.
3. If you really want to know what your bizarre code does - why don't you run it through the debugger yourself????
You have Visual Studio, you compiled the code, the next logical step is to see if it does what you intended.
-Vit-
25th April 2011, 22:27
JD, you don't understand even the most basic programming concepts. I suggest you spend time studying instead of writing posts to torture us.
This is a movie shuffler in an Avisynth script:
# Pick a number to give a different order
Order = 3436
# Push 7 clips onto an array called "Movies"
ArrayPush( "Movies", DirectShowSource("1.mp4") )
ArrayPush( "Movies", DirectShowSource("2.mp4") )
ArrayPush( "Movies", DirectShowSource("3.mp4") )
ArrayPush( "Movies", DirectShowSource("4.mp4") )
ArrayPush( "Movies", DirectShowSource("5.mp4") )
ArrayPush( "Movies", DirectShowSource("6.mp4") )
ArrayPush( "Movies", DirectShowSource("7.mp4") )
# Shuffle the 7 movies
Shuffle( "Movies", 7, Order ) # Leave the Order parameter out for a random order each second
# Pop and splice the randomly ordered movies from the array
ArrayPop("Movies") + \
ArrayPop("Movies") + \
ArrayPop("Movies") + \
ArrayPop("Movies") + \
ArrayPop("Movies") + \
ArrayPop("Movies") + \
ArrayPop("Movies")
# Randomly shuffle an array (see below) of given size
# Seed parameter can be given for specific shuffle, or omitted for
# a shuffle based on time of day (different shuffle each second)
function Shuffle( string Array, int Size, int "Seed")
{
rand = defined(Seed) ? Random(Seed) : Random()
swap = rand % Size
Size = Size - 1
a = ArrayGet( Array, Size )
b = ArrayGet( Array, swap )
ArraySet( Array, Size, b )
ArraySet( Array, swap, a )
(Size > 1) ? Shuffle( Array, Size, rand ) : NOP()
}
# Simple 16 bit random number generator, returns value 0 to 65535
# Pass last random number to seed next one. For initial seed pass user-chosen
# value or pass nothing to seed based on time of day (in seconds only)
function Random( int "Seed" )
{
Seed = default( Seed, Int(Value(Time("%S")) + 60 * (Value(Time("%M")) + 60 * Value(Time("%H")))) ) % 65536
return (seed * 26681 + 1) % 65536
}
# Simple array-like implementation with globals. No real error checking
function ArrayPush( string Array, val Value )
{
ArraySizeVar = Array + "Size"
index = 0
try { index = Eval( ArraySizeVar ) }
catch(e){ Eval( "global " + ArraySizeVar + "=0" ) }
Eval( "global " + Array + String(index) + "= Value" )
Eval( "global " + ArraySizeVar + "=" + ArraySizeVar + "+1" )
}
function ArrayPop( string Array )
{
ArraySizeVar = Array + "Size"
Eval( "global " + ArraySizeVar + "=" + ArraySizeVar + "-1" )
index = Eval( ArraySizeVar )
return Eval( Array + String(index) )
}
function ArraySet( string Array, int Index, val Value )
{
Eval( "global " + Array + String(index) + "= Value" )
}
function ArrayGet( string Array, int Index )
{
return Eval( Array + String(index) )
}
Jeremy Duncan
25th April 2011, 22:35
Let's try this a different way.
Aside from whatever you are saying about the number of frames, what aspects of the previously posted python script dont meet your needs?
I just opened the file and looked at the code and didn't see any boolean math for each clip.
So I said it's not what I was looking for. But, I would like to try it. Could you tell me how to load it into avsp and open the clips folder with avsp? :) I want to see how cool it looks. :cool:
Groucho2004,
Write how to run it through the debugger. I tried before but the debugger confused me.
-Vit-,
I will do that. No boolean math in there though. But not to worry.
Everyone; don't worry. I will go back to the C manual. No need to worry.
:thanks: :helpful:
I'm not trying to get a random movie shuffle. I'm trying to get the movie shuffle to be based on boolean true false, so it's predictable.
The goal is if it's based on boolean math not just a random unpredictable shuffle I can tweak the boolean math to create a shuffle that looks like a very good youtube movie hash.
I would like to know if it the math in post #15 does what I think it does? :) If not then point out the part of the code that is written wrong.
-Vit-
25th April 2011, 22:50
It would help if you read before you write. I put a comment on the Shuffle line about how to make a predictable random order. I have edited the post so it is even more clear. Just play with that Order number until you're happy.
Regarding your code in #15, it is wrong in so many ways that my head hurts.
My script uses the Fisher-Yates shuffle algorithm coupled with a Linear Congruential random number generator. Please go read.
Jeremy Duncan
25th April 2011, 22:57
Wow! Thanks -Vit-. I will definitely save that to a file and while I learn C I will reference this code to see how you did it. :)
Thank you very much.
Jeremy Duncan
25th April 2011, 23:38
-Vit-,
May I ask if there is a textbook on how to write that code? I asked in a different forum and they said it's not C or C++ but some varient. Do you have a link to a textbook on how to write that code? :)
Gavino
26th April 2011, 00:07
May I ask if there is a textbook on how to write that code? I asked in a different forum and they said it's not C or C++ but some varient. Do you have a link to a textbook on how to write that code? :)
Try this (http://avisynth.org/mediawiki/Main_Page#New_to_AviSynth_-_start_here).
Jeremy, you have excelled yourself with this thread.
I can only assume that you are a highly skilled troll who is having a good laugh at our expense.
Groucho2004
26th April 2011, 00:25
I can only assume that you are a highly skilled troll who is having a good laugh at our expense.
I don't think so. Looking at the stuff he posted it is clear that he is trying to invent some C/C++/Avisynth script hybrid plugin thingy, mixing everything together nicely. I think he's just confused and can't even recognize Avisynth scripts any more.
Gavino
26th April 2011, 01:27
Yeah, I was being ironic. ;)
I haven't seen C code like that since they stopped running the IOCCC (http://en.wikipedia.org/wiki/Obfuscated_C) (but those programs actually worked).
Jeremy Duncan
26th April 2011, 01:36
I know your upset right now, but I thought that if I put this out there I would get some information, so I asked.
I'm going to learn C before trying to learn C++ then trying avisynth stuff.
At the rate I learn it will take 3 years to learn c and c++ before I start into avisynth stuff. I googled the terms "arrayget", "arrayset" and got no guide. But then I tried get and set and pop as c++ terms and sure enough there they were.
Groucho2004
26th April 2011, 15:39
I googled the terms "arrayget", "arrayset" and got no guide. But then I tried get and set and pop as c++ terms and sure enough there they were.
Here's a hint:
What Vit posted is written in a script language that starts with an "A".
aegisofrime
26th April 2011, 16:41
Arrayget and arrayset are functions that Vit created; They aren't built in Avisynth functions, which is why you don't get anything with Google. I only took a crash course in pseudocode and even I know this...
Jeremy Duncan
26th April 2011, 21:14
Thanks to you people I have found a nice book to read on how to wite and code C.
After reading it a bit I found how I was writing the if and else code wrong before.
So I re-wrote the code fixing those errors and I also fixed to boolean math a bit so it's more random.
I hope you don't mind, but after doing all that I want to post the work I did.
:thanks:
If Gavino or -Vit- say it works, then may I ask somebody to make it into a avsi file or a py file so i can actually run it with real media files?
Here you go;
bad code removed
:helpful:
Groucho2004
26th April 2011, 21:46
Please stop cluttering the board with this insanity!
Your 300 lines long if-else monstrosity does nothing but assign different values to the variables. Once.
Your "code" makes no sense. Stop it.
Maybe you are trolling after all...
Also, if you think you need three years of learning programming to master this task you should possibly sit back and re-evaluate your goals.
Jeremy Duncan
26th April 2011, 22:03
:eek:Watch how loosely you sling around that T word, Groucho. :mad:
If the code I posted in my previous reply works or not is my first concern, then my second concern is if it acts as a randomizer as that is all it is.
If it makes sense to YOU is not my concern, right now. maybe later if this all works then we can post on the sensibility of the code.
Don't get spooked, Groucho. It's ok... :) I'm not Trolling, ok.
Guest
26th April 2011, 22:06
This is code/development related so can't remain in Avisynth Usage.
I can move it to Development or Newbies. The latter seems more appropriate given the content (e.g., "C" script and two=10), but let's be generous and choose the former.
Jeremy Duncan
26th April 2011, 22:09
Move it to development, since in the newbies forum I can't expect a newbie or newbie helper to help develop a plugin...can I?
Groucho2004
26th April 2011, 22:14
If it makes sense to YOU is not my concern
The question is if it makes sense to you. It sure doesn't make sense to anybody else.
Guest
26th April 2011, 22:17
Move it to development, since in the newbies forum I can't expect a newbie or newbie helper to help develop a plugin...can I? Your code does not appear to be a plugin. And Newbies is widely read, not only by Newbies. The Newbies forum gives you a little cover for deficiencies; in Development you may find things a bit more challenging. Experienced developers looking at your post are going to dismiss it anyway, I'm afraid.
E.g., all this one = 1 stuff. Do you know that you can index an array with a variable and eliminate all that error-prone repetition? If you grow to a thousand files, will you write thousands of lines of code, or will you choose a way that does it in a few lines? If you use an array, you can easily change the order by swapping array elements, etc.
Your way is absurd just from a usage perspective. If a user wants to work with a different number of files, he has to rewrite and recompile your tool?
Jeremy Duncan
26th April 2011, 22:31
You know if it should be in Newbies or not, I trust your judgement. So move it to newbies. I'm writing it now so later when I know C and C++ I have a foundation to go to too grow and develop more.
You know how code starts small and you do it right, then you add another section and you do that section right, then you add more code and you do that section right and when your all done your code is fancy. I'm doing it like that by starting with base code and then moving up to fancier code later.
Groucho. That circumference example is what I'm using. You wrote that 3 is always greater than 1 and 2 is always less than 3. This is "linear logic" (a term I just made up). That is the line to the centre of the circle is a straight line from the circumference to the centre.
That's not random.
So I say if that is true, that is linear logic is true, then randomize the sequence by making the variable random.
Or else, if the linear logic is false then there is no need to randomize the variable, so variable equals variable.
Guest
26th April 2011, 22:39
I'm doing it like that by starting with base code and then moving up to fancier code later. Great, that's the way to go.
My suggestion to you is that if you see something repeated a lot times with only a small variation, then it is probably an unrolled loop that you should roll up.
Good luck!
when your all done your code is fancy Hmm, a new idea for software quality metrics.
Gavino
26th April 2011, 22:51
If Gavino or -Vit- say it works, then may I ask somebody to make it into a avsi file or a py file so i can actually run it with real media files?
For heaven's sake Jeremy! Why are you continuing with this?
You seem unable to see that your program is complete and utter nonsense, and so is your explanation of it.
And C code cannot be turned into an avsi or py file.
Why can't you just use -Vit-'s script or Zarxrax's AvsP macro?
It's obvious you don't have the right skills to be a programmer (just as I'm not cut out to be a weightlifter).
You are enthusiastic and have a very unusual way of seeing things, perhaps you could be successfull in some sort of artistic activity. (Seriously.)
Jeremy Duncan
26th April 2011, 22:56
Gavino,
You didn't answer if the code works.
Gavino
26th April 2011, 22:59
I can't take any more, I give up!!!
Groucho2004
26th April 2011, 23:48
Groucho. That circumference example is what I'm using. You wrote that 3 is always greater than 1 and 2 is always less than 3. This is "linear logic" (a term I just made up). That is the line to the centre of the circle is a straight line from the circumference to the centre.
That's not random.
So I say if that is true, that is linear logic is true, then randomize the sequence by making the variable random.
Or else, if the linear logic is false then there is no need to randomize the variable, so variable equals variable.
Now it all makes sense. :rolleyes:
Jeremy Duncan
27th April 2011, 00:52
Your 300 lines long if-else monstrosity does nothing but assign different values to the variables. Once.
Here is a random code, I think that does more than the bug you mentioned:
bad code removed
:helpful:
-Vit-
27th April 2011, 01:38
Your code does not work. It doesn't randomize anything. It just reproduces the order that you manually type into the program.
Below is your code reproduced exactly, but with additional code to display the values in the variables 'one' to 'twenty-seven'.
To make sure you can see the text output, create a new project in Visual Studio of type "Win32 Console Application" (unless your project was already of that type).
Your for loop also counts one too far, corrupting memory and throwing a run-time error when you quit.
The output of the program is:
Contents of variables 'one' to 'twenty-seven':
1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 26 27
Press 'Return to quit
#include <iostream>
#include <stdio.h>
typedef struct movie {
int audio;
double fps;
} Movie;
int main( void )
{
Movie movies[27];
int one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twenty_one, twenty_two, twenty_three, twenty_four, twenty_five, twenty_six, twenty_seven;
one=1;
two=2;
three=3;
four=4;
five=5;
six=6;
seven=7;
eight=8;
nine=9;
ten=10;
eleven=11;
twelve=12;
thirteen=13;
fourteen=14;
fifteen=15;
sixteen=16;
seventeen=17;
eighteen=18;
nineteen=19;
twenty=20;
twenty_one=21;
twenty_two=22;
twenty_three=23;
twenty_four=24;
twenty_five=25;
twenty_six=26;
twenty_seven=27;
if((two<=three)&&(three>=one)&&(one=one)){
two=three;
}
else{
two=two;
}
/*break one*/
if((three<=four)&&(four>=two)&&(two=two)){
three=four;
}
else{
three=three;
}
/*break two*/
if((four<=five)&&(five>=three)&&(three=three)){
four=five;
}
else{
four=four;
}
/*break three*/
if((five<=six)&&(six>=four)&&(four=four)){
five=six;
}
else{
five=five;
}
/*break four*/
if((six<=seven)&&(seven>=five)&&(five=five)){
six=seven;
}
else{
six=six;
}
/*break five*/
if((seven<=eight)&&(eight>=six)&&(six=six)){
seven=eight;
}
else{
seven=seven;
}
/*break six*/
if((eight<=nine)&&(nine>=seven)&&(seven=seven)){
eight=nine;
}
else{
eight=eight;
}
/*break seven*/
if((nine<=ten)&&(ten>=eight)&&(eight=eight)){
nine=ten;
}
else{
nine=nine;
}
/*break eight*/
if((ten<=eleven)&&(eleven>=nine)&&(nine=nine)){
ten=eleven;
}
else{
ten=ten;
}
/*break nine*/
if((eleven<=twelve)&&(twelve>=ten)&&(ten=ten)){
eleven=twelve;
}
else{
eleven=eleven;
}
/*break ten*/
if((twelve<=thirteen)&&(thirteen>=eleven)&&(eleven=eleven)){
twelve=thirteen;
}
else{
twelve=twelve;
}
/*break eleven*/
if((thirteen<=fourteen)&&(fourteen>=twelve)&&(twelve=twelve)){
thirteen=fourteen;
}
else{
thirteen=thirteen;
}
/*break twelve*/
if((fourteen<=fifteen)&&(fifteen>=thirteen)&&(thirteen=thirteen)){
fourteen=fifteen;
}
else{
fourteen=fourteen;
}
/*break thirteen*/
if((fifteen<=sixteen)&&(sixteen>=fourteen)&&(fourteen=fourteen)){
fifteen=sixteen;
}
else{
fifteen=fifteen;
}
/*break fourteen*/
if((sixteen<=seventeen)&&(seventeen>=fifteen)&&(fifteen=fifteen)){
sixteen=seventeen;
}
else{
sixteen=sixteen;
}
/*break fifteen*/
if((seventeen<=eighteen)&&(eighteen>=sixteen)&&(sixteen=sixteen)){
seventeen=eighteen;
}
else{
seventeen=seventeen;
}
/*break sixteen*/
if((eighteen<=nineteen)&&(nineteen>=seventeen)&&(seventeen=seventeen)){
eighteen=nineteen;
}
else{
eighteen=eighteen;
}
/*break seventeen*/
if((nineteen<=twenty)&&(twenty>=eighteen)&&(eighteen=eighteen)){
nineteen=twenty;
}
else{
nineteen=nineteen;
}
/*break eighteen*/
if((twenty<=twenty_one)&&(twenty_one>=nineteen)&&(nineteen=nineteen)){
twenty=twenty_one;
}
else{
twenty=twenty;
}
/*break nineteen*/
if((twenty_one<=twenty_two)&&(twenty_two>=twenty)&&(twenty=twenty)){
twenty_one=twenty_two;
}
else{
twenty_one=twenty_one;
}
/*break twenty*/
if((twenty_two<=twenty_three)&&(twenty_three>=twenty_one)&&(twenty_one=twenty_one)){
twenty_two=twenty_three;
}
else{
twenty_two=twenty_two;
}
/*break twenty_one*/
if((twenty_three<=twenty_four)&&(twenty_four>=twenty_two)&&(twenty_two=twenty_two)){
twenty_three=twenty_four;
}
else{
twenty_three=twenty_three;
}
/*break twenty_two*/
if((twenty_four<=twenty_five)&&(twenty_five>=twenty_three)&&(twenty_three=twenty_three)){
twenty_four=twenty_five;
}
else{
twenty_four=twenty_four;
}
/*break twenty_three*/
if((twenty_five<=twenty_six)&&(twenty_six>=twenty_four)&&(twenty_four=twenty_four)){
twenty_five=twenty_six;
}
else{
twenty_five=twenty_five;
}
/*break twenty_five*/
// Output the contents of the variables
std::cout << "Contents of variables 'one' to 'twenty-seven':" << std::endl;
std::cout << one << " "
<< two << " "
<< three << " "
<< four << " "
<< five << " "
<< six << " "
<< seven << " "
<< eight << " "
<< nine << " "
<< ten << " "
<< eleven << " "
<< twelve << " "
<< thirteen << " "
<< fourteen << " "
<< fifteen << " "
<< sixteen << " "
<< seventeen << " "
<< eighteen << " "
<< nineteen << " "
<< twenty << " "
<< twenty_one << " "
<< twenty_two << " "
<< twenty_three << " "
<< twenty_four << " "
<< twenty_five << " "
<< twenty_six << " "
<< twenty_seven << std::endl << std::endl;
for ( one = 1; one <= twenty_seven; ++one ) {
/* the name of the movie file corresponds to the array element
* e.g. movie "5.mp4" is movies[5], movie "6.mp4" is movies[6]...
*/
movies[one].audio = 0;
movies[one].fps = 23.976;
}
std::cout << "Press 'Return' to quit" << std::endl;
std::cin.get();
return 0;
}
Guest
27th April 2011, 01:39
It's fancy now, so we are done.
BTW, a random shuffle can be done in a few lines, e.g.:
http://rgrig.blogspot.com/2005/04/random-permutation.html
-Vit-
27th April 2011, 01:51
Which is the same algorithm as the Fisher-Yates shuffle I used (http://forum.doom9.org/showthread.php?p=1495575#post1495575) earlier, although this one is 1-based, and I made mine recursive to suit Avisynth.
Guest
27th April 2011, 01:55
You didn't tell him all his else clauses are superfluous. :)
else{
twenty_one=twenty_one;
}
is a no-op.
-Vit-
27th April 2011, 01:56
Pretty much his entire code is a no-op, you have to type the result you want into the program ;)
Jeremy Duncan
27th April 2011, 03:41
Thank you -Vit-, I got testing and got these results:
C:\Users\Brian\Desktop>samp.exe
Contents of variables 'one' to 'twenty-seven':
1 2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 27
Press 'Return' to quit
C:\Users\Brian\Desktop>
This is the retuned code, thanks to your help:
#include <iostream>
#include <stdio.h>
typedef struct movie {
int audio;
double fps;
} Movie;
int main( void )
{
Movie movies[27];
int one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twenty_one, twenty_two, twenty_three, twenty_four, twenty_five, twenty_six, twenty_seven;
one=1;
two=2;
three=3;
four=4;
five=5;
six=6;
seven=7;
eight=8;
nine=9;
ten=10;
eleven=11;
twelve=12;
thirteen=13;
fourteen=14;
fifteen=15;
sixteen=16;
seventeen=17;
eighteen=18;
nineteen=19;
twenty=20;
twenty_one=21;
twenty_two=22;
twenty_three=23;
twenty_four=24;
twenty_five=25;
twenty_six=26;
twenty_seven=27;
/*break one*/
if((twenty_five<=twenty_six)&&(twenty_six>=twenty_four)){
twenty_five=twenty_three;
}
else{
twenty_five=twenty_five;
}
/*break two*/
if((twenty_four<=twenty_five)&&(twenty_five>=twenty_three)){
twenty_four=twenty_two;
}
else{
twenty_four=twenty_four;
}
/*break three*/
if((twenty_three<=twenty_four)&&(twenty_four>=twenty_two)){
twenty_three=twenty_one;
}
else{
twenty_three=twenty_three;
}
/*break four*/
if((twenty_two<=twenty_three)&&(twenty_three>=twenty_one)){
twenty_two=twenty;
}
else{
twenty_two=twenty_two;
}
/*break five*/
if((twenty_one<=twenty_two)&&(twenty_two>=twenty)){
twenty_one=nineteen;
}
else{
twenty_one=twenty_one;
}
/*break six*/
if((twenty<=twenty_one)&&(twenty_one>=nineteen)){
twenty=eighteen;
}
else{
twenty=twenty;
}
/*break seven*/
if((nineteen<=twenty)&&(twenty>=eighteen)){
nineteen=seventeen;
}
else{
nineteen=nineteen;
}
/*break eight*/
if((eighteen<=nineteen)&&(nineteen>=seventeen)){
eighteen=sixteen;
}
else{
eighteen=eighteen;
}
/*break nine*/
if((seventeen<=eighteen)&&(eighteen>=sixteen)){
seventeen=fifteen;
}
else{
seventeen=seventeen;
}
/*break ten*/
if((sixteen<=seventeen)&&(seventeen>=fifteen)){
sixteen=fourteen;
}
else{
sixteen=sixteen;
}
/*break eleven*/
if((fifteen<=sixteen)&&(sixteen>=fourteen)){
fifteen=thirteen;
}
else{
fifteen=fifteen;
}
/*break twelve*/
if((fourteen<=fifteen)&&(fifteen>=thirteen)){
fourteen=twelve;
}
else{
fourteen=fourteen;
}
/*break thirteen*/
if((thirteen<=fourteen)&&(fourteen>=twelve)){
thirteen=eleven;
}
else{
thirteen=thirteen;
}
/*break fourteen*/
if((twelve<=thirteen)&&(thirteen>=eleven)){
twelve=ten;
}
else{
twelve=twelve;
}
/*break fifteen*/
if((eleven<=twelve)&&(twelve>=ten)){
eleven=nine;
}
else{
eleven=eleven;
}
/*break sixteen*/
if((ten<=eleven)&&(eleven>=nine)){
ten=eight;
}
else{
ten=ten;
}
/*break seventeen*/
if((nine<=ten)&&(ten>=eight)){
nine=seven;
}
else{
nine=nine;
}
/*break eighteen*/
if((eight<=nine)&&(nine>=seven)){
eight=six;
}
else{
eight=eight;
}
/*break nineteen*/
if((seven<=eight)&&(eight>=six)){
seven=five;
}
else{
seven=seven;
}
/*break twenty*/
if((six<=seven)&&(seven>=five)){
six=four;
}
else{
six=six;
}
/*break twenty_one*/
if((five<=six)&&(six>=four)){
five=three;
}
else{
five=five;
}
/*break twenty_two*/
if((four<=five)&&(five>=three)){
four=two;
}
else{
four=four;
}
/*break twenty_three*/
if((three<=four)&&(four>=two)){
three=one;
}
else{
three=three;
}
/*break twenty_five*/
// Output the contents of the variables
std::cout << "Contents of variables 'one' to 'twenty-seven':" << std::endl;
std::cout << one << " "
<< two << " "
<< three << " "
<< four << " "
<< five << " "
<< six << " "
<< seven << " "
<< eight << " "
<< nine << " "
<< ten << " "
<< eleven << " "
<< twelve << " "
<< thirteen << " "
<< fourteen << " "
<< fifteen << " "
<< sixteen << " "
<< seventeen << " "
<< eighteen << " "
<< nineteen << " "
<< twenty << " "
<< twenty_one << " "
<< twenty_two << " "
<< twenty_three << " "
<< twenty_four << " "
<< twenty_five << " "
<< twenty_six << " "
<< twenty_seven << std::endl << std::endl;
for ( one = 1; one <= twenty_seven; ++one ) {
/* the name of the movie file corresponds to the array element
* e.g. movie "5.mp4" is movies[5], movie "6.mp4" is movies[6]...
*/
movies[one].audio = 0;
movies[one].fps = 23.976;
}
std::cout << "Press 'Return' to quit" << std::endl;
std::cin.get();
return 0;
}
Because some numbers are repeated does this mean there is a bug that will cause a crash or something like that, because I think having repeated clips is ok?
:thanks:
-Vit-
27th April 2011, 04:16
Your code still doesn't work.
You have had to manually type in your first if statement to say "twenty_five=twenty_three" [and now you've edited it, the code and results don't match]
And look what the 25th number in your output is... it's 23. What a surprise. The program does nothing useful at all.
But you want a better solution. Here it is. This C program does exactly the same shuffle as yours, but I've optimized it:
one=1;
two=2;
three=1;
four=4;
five=3;
six=6;
seven=5;
eight=8;
nine=7;
ten=10;
eleven=9;
twelve=12;
thirteen=11;
fourteen=14;
fifteen=13;
sixteen=15;
seventeen=15;
eighteen=18;
nineteen=17;
twenty=20;
twenty_one=19;
twenty_two=22;
twenty_three=21;
twenty_four=24;
twenty_five=23; // Look: twenty-five = twenty-three!
twenty_six=26;
twenty_seven=27;
Jeremy Duncan
27th April 2011, 07:21
Hi -Vit-
Notice the code If and Else? These use variable names, not variable values.
There's a reason for that.
Now that I have the randomization working on every other frame, (I have a typo in the code I will fix after). I can worry about adding the frame number values to the variable name value.
So; int one=1 will become; int one = x number of frames from the clip.
But I have no idea on how to do this. :)
The first step was to get the clips randomized every other clip.
I have edited the code I posted before. And the results show 15 isn't repeated now. So the code is all random.
I hoping now that it works this far somebody can help me add the frame numbers as a variable name so it works like this:
int a;
a=(b= x number of frames from the clip)
Maybe I will have to call the video twice like this:
step one;
a=directshowsource(clip)
b=a.number of frames in clip a
step two
int a;
a=b
Groucho2004
27th April 2011, 08:34
Jeremy,
It would be so much easier if you'd listen to the advice you're getting.
I have been programming for more than 20 years and I'm telling you that your C/C++ skills do not go beyond "Hello World" (yet). Although what you're trying to do is rather simple from my point of view, it's way beyond what you can do at this time.
So, your options from here on are:
continue posting these bizarre code fragments wasting your and our time
learn programming and then try again
find someone who would do this for you
It's up to you.
Jeremy Duncan
27th April 2011, 09:52
Hi Groucho,
Look at this fancy code:
Fancy code in my post below. It's been improved and I didn't want two versions floating around.
This is the answers it gives me:
edited out results
It uses a array, it's small code which is very fancy, but look at the answers it gives.
One result is totally random from the next to the next: all three results are different.
This is not what I want.
I want my randomizer to give the Same answer each time, and let the number of frames be the randomizer; or some other variable that distinguishes the clips besides frame numbers in a clip, like clip length/time, and add this sum value to the int variable and let these values be dynamic.
So the ints can use different clips and each time the int uses a different clip - the value that clip has that makes it a randomizes is changed too. This way the int value changes whenever the clip it points to changes.
As far as I can tell you either don't know what I'm saying, or maybe I'm not being clear enough for you too understand what I am saying. :thanks: :helpful:
GodofaGap
27th April 2011, 10:29
I want my randomizer to give the Same answer each time,
Then use the same seed each time. Right now you are using time(NULL) which isn't a constant.
I think you are struggling with the basic concept of what a random number in C/C++ is, and you really should do some reading on it.
Also, you apparently find it very difficult to explain what it is you want and until you can you should stop coding and figure that out first. If you can't explain it to yourself or us, you certainly won't be able to explain it to a computer.
Groucho2004
27th April 2011, 10:30
As far as I can tell you either don't know what I'm saying, or maybe I'm not being clear enough for you too understand what I am saying.
Yes, the only conclusion is that we don't speak the same language.
Jeremy Duncan
27th April 2011, 10:35
Then use the same seed each time. Right now you are using time(NULL) which isn't a constant.
That actually works. :thanks:
This ones a bit better than the other one, but I can't add boolean to it to get the same results as my large code.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main (void)
{ int play[25];
int x, y, t;
// init array
for (x = 0; x <= 25; x++)
play[x] = x + 1;
// shuffle playlist
// shuffle playlist
for ( x = 24; x >0; x--){
y = rand() % x;
t = play[y];
play[y] = play[x];
play[x] = t;
}
// output result
for (x=0; x<25; x++) printf("%d ", play[x]);
return 0; }
Gavino
27th April 2011, 14:25
Why are you continuing to ignore the advice of people here, and on the other forum (http://cboard.cprogramming.com/c-programming/137280-i-am-very-new-c-student%3B-i-want-your-help-creating-random-video-sequence-sw-2.html) you have been posting to?
Stop now. Desist.
You have been given two perfectly good solutions to your problem. If they don't quite match what you want (and it's still not clear to most of us what that is), amend them to do so.
As for you learning and understanding C/C++, with all due respect that's as likely as a fish learning to ride a bicycle.
-Vit-
27th April 2011, 14:34
So now you have exactly the same shuffle algorithm that I gave you earlier (or rather, someone else has given you the same answer).
OK, here is a comprehensive solution to the OP. It can do a fixed random shuffle (which is what you want), or you can type in values to control some awesome "boolean maths".
It can output an AVS script or a single MP4 file. Read the comments in the code before replying with any stupid.
Apologies to the coders out there for the insane parts of the code below
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
// Mix actions (see below)
const int SHUFFLE = 0;
const int USER_CONTROL = 1;
// Output actions (see below)
const int MAKE_MP4 = 0;
const int MAKE_AVS = 1;
// Choose mix action
// - SHUFFLE: Shuffle clips randomly but with a fixed order selected by 'shuffleorder' below
// - USER_CONTROL: Type in special values for complete control over the mix using "boolean math" (spoken excitedly with emphasis, like an ad)
int mixaction = USER_CONTROL;
// Choose output action
// - MAKE_MP4: Use mp4box to make a single "mix.mp4" from the shuffle (need mp4box.exe & js32.dll in the project folder)
// - MAKE_AVS: Create a "mix.avs" avisynth file that you can play or serve to another app or whatever
// Assumes there are 27 clips in "C:\Clips\" called "1.mp4", "2.mp4", etc.
int outputaction = MAKE_MP4;
// Choose fixed order for random shuffle (doesn't affect USER_CONTROL mode)
unsigned int shuffleorder = 3436;
// Values for the absolutely vital, patented "boolean math" used in USER_CONTROL mode (wow!)
int booleans[25] = { 2, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25 };
// Init playlist array
int play[25];
int x, y, t;
for (x = 0; x < 25; x++)
{
play[x] = x + 2;
}
if (mixaction == SHUFFLE)
{
// Fisher-Yates shuffle (done properly) of playlist with specific seed
srand(shuffleorder);
for (x = 24; x > 0; x--)
{
y = rand() % (x+1);
t = play[y];
play[y] = play[x];
play[x] = t;
}
}
else if (mixaction == USER_CONTROL)
{
// User control mode, do some complex "boolean math" to give complete control over the mix order (oooh!)
for (x = 0; x < 25; x++)
{
if ((play[x] >= booleans[x]) || (play[x] <= booleans[x]) || (play[x] = booleans[x])) // [I know, I know, quite deliberate...]
{
play[x] = booleans[x];
}
else
{
play[x] = play[x];
}
}
}
if (outputaction == MAKE_MP4)
{
char catcmd[2048]; // Make sure this is big enough for command
int index = 0;
index += sprintf(&catcmd[index], "mp4box.exe -cat \"C:\\Clips\\1.mp4\"");
for (x = 0; x < 25; x++)
{
index += sprintf(&catcmd[index], " -cat \"C:\\Clips\\%d.mp4\"", play[x]);
}
sprintf(&catcmd[index], " -cat \"C:\\Clips\\27.mp4\" mix.mp4");
system( catcmd );
system( "mix.mp4" );
}
else if (outputaction == MAKE_AVS)
{
FILE* file = fopen("mix.avs", "w");
fprintf(file, "DirectShowSource(\"C:\\Clips\\1.mp4\", audio=false, 23.976) + \\\n");
for (x = 0; x < 25; x++)
{
fprintf( file, "DirectShowSource(\"C:\\Clips\\%d.mp4\", audio=false, 23.976) + \\\n", play[x]);
}
fprintf(file, "DirectShowSource(\"C:\\Clips\\27.mp4\", audio=false, 23.976)\n");
fclose( file );
}
return 0;
}
kypec
27th April 2011, 20:33
Vit, you have my absolute admiration for your endless patience with Jeremy's persistence :) Hats off!
Jeremy Duncan
27th April 2011, 21:06
Thank you -Vit-, I will now cease from talking about this anymore.
Your :cool:.
Jeremy Duncan
28th April 2011, 09:35
doubting Thomas code removed, see my post below for a explaination.
Gavino
28th April 2011, 10:00
I made it into a dll...
Once again, you have shown that you have no understanding of what you are doing.
The code is clearly for a free-standing program, ie a .exe, not a dll.
Did you read the source file comments that -Vit- spent his valuable time on?
Jeremy Duncan
28th April 2011, 10:14
Gavino,
You know your right. But I looked at the code and the thought that it was a exe was almost too good to be true, so I disbelieved it and thought it was a dll.
So I listened to you and downloaded the files he mentioned and put the exe I compiled in the clips folder and ran the program in the cmd prompt and it compiled the clips and ran them through realplayer.
I was wrong to doubt the code and think how could -Vit- be so kind as to give me a exe...I'm sorry for doubting you -Vit-, I thought about your work all day before getting the nerve to even look at it and that's why I came here for your help.
Thank -Vit-, really man. :thanks:
Groucho2004
28th April 2011, 10:30
But I looked at the code and the thought that it was a exe was almost too good to be true, so I disbelieved it and thought it was a dll.
Sometimes I wonder what planet you're from.
BTW, what happened to "I will now cease from talking about this anymore"?
Jeremy Duncan
28th April 2011, 11:20
Groucho,
I looked it over and I'm really amazed at this work I was given.
It's not everyday somebody helps you. Thanks -Vit-.
LaTo
28th April 2011, 11:28
This thread is awesome :D
Jeremy Duncan
28th April 2011, 12:10
Talking about that code -Vit- made. I'm using the clips folder from the first post, and it's about a minute long with all the clips played, but the exe makes it 7:40 minutes long.
So the random sequence keeps looping after it plays it's 27 clips.
And user_control and default play the same order of clips. And I know that the randomizer that's default makes the clip order really random, yet everytime they play in the same order.
I'm typing this into cmd prompt:
mix.exe or, mix.exe user_control or mix.exe mixaction = USER_CONTROL
Looks like the program has 2 bugs anyway. What else could it be? I compiled your code to a exe, I ran the program on default and the settings in the file.
Gavino
28th April 2011, 12:15
You know your right. But I looked at the code and the thought that it was a exe was almost too good to be true, so I disbelieved it and thought it was a dll.
Even if you did think it was a dll, how on earth did you expect your script (now deleted) to do anything?
If I recall, you had something like this:
LoadPlugin("... dll")
DirectShowSource("1.mp4", ...)
...
DirectShowSource("27.mp4", ...)
converttoyv12
To use a plugin, you have to call some function from it - just loading it achieves nothing.
Groucho2004
28th April 2011, 12:37
Talking about that code -Vit- made. I'm using the clips folder from the first post, and it's about a minute long with all the clips played, but the exe makes it 7:40 minutes long.
So the random sequence keeps looping after it plays it's 27 clips.
And user_control and default play the same order of clips. And I know that the randomizer that's default makes the clip order really random, yet everytime they play in the same order.
I'm typing this into cmd prompt:
mix.exe or, mix.exe user_control or mix.exe mixaction = USER_CONTROL
You obviously don't understand a single statement in the code Vit posted.
Looks like the program has 2 bugs anyway. What else could it be?
Hm, what else could it be?
-Vit-
28th April 2011, 12:44
Talking about that code -Vit- made. I'm using the clips folder from the first post, and it's about a minute long with all the clips played, but the exe makes it 7:40 minutes long.
Dunno, don't care. Probably your mistake.
And user_control and default play the same order of clips. And I know that the randomizer that's default makes the clip order really random, yet everytime they play in the same order.
I'm typing this into cmd prompt:
mix.exe or, mix.exe user_control or mix.exe mixaction = USER_CONTROL
You must edit the code and recompile to change the mixaction, shuffleorder or anything else. If you want command line support you'll have to pay.
I will now cease from talking about this anymore.
Groucho2004
28th April 2011, 12:49
If you want command line support you'll have to pay.
<DrEvil>
Muahahaha.
</DrEvil>
noee
28th April 2011, 12:55
JD: read here (http://crasseux.com/books/ctutorial/argc-and-argv.html#argc%20and%20argv)
And I thought the car-enthusiast forums were fun....
Groucho2004
28th April 2011, 13:08
Why are you continuing to ignore the advice of people here, and on the other forum (http://cboard.cprogramming.com/c-programming/137280-i-am-very-new-c-student%3B-i-want-your-help-creating-random-video-sequence-sw-2.html) you have been posting to?
Wow, I just looked at the thread on the other forum. He's driving people nuts all over the place. What is wrong with this guy?
Gavino
28th April 2011, 13:21
I hope this thread will teach people to steer clear of any Avisynth builds by Jeremy Duncan, as he clearly has no technical credibility whatsoever.
He has good intentions, but is the perfect example of the saying "a little knowledge is a dangerous thing".
kypec
28th April 2011, 14:25
This thread is awesome :D
Exactly!
And I thought the car-enthusiast forums were fun....
Thanks for the tip, will look on those one day as well.
I just hope this thread will eventually turn into sticky "Jeremy Duncan's step-by-step tutorial how not to write programs":p
Guest
28th April 2011, 16:01
Let's keep it civil and avoid personal attacks, else rule 4 can apply. Thank you.
Gavino
28th April 2011, 17:41
I don't know if neuron2's remark was aimed at me, or simply at forestalling this thread from going in an unpleasant direction, but I have nothing personal against Jeremy and have always tried to help him whenever I could.
But as this a technical forum, it's surely right that a person's technical expertise is open to question. Experienced members can immediately see his complete lack of technical understanding, but others may not be aware of this and waste time on his ramblings.
I am particularly concerned with his meddling in Avisynth.
Some of his misguided 'fixes' found their way into SEt's builds and I'm not even sure were totally cleaned up. That was in 2009 and he now admits he doesn't even know the first thing about C programming.
Groucho2004
28th April 2011, 17:56
I don't know if neuron2's remark was aimed at me, or simply at forestalling this thread from going in an unpleasant direction, but I have nothing personal against Jeremy and have always tried to help him whenever I could.
I think it was aimed at several of us. Of course nobody has any grudge against Jeremy but he has a way of pushing your buttons.
Experienced members can immediately see his complete lack of technical understanding, but others may not be aware of this and waste time on his ramblings.
Exactly.
I am particularly concerned with his meddling in Avisynth.
Some of his misguided 'fixes' found their way into SEt's builds and I'm not even sure were totally cleaned up. That was in 2009 and he now admits he doesn't even know the first thing about C programming.
I can fully understand his motivation but - as you mentioned already - there seems to be an aptitude problem and he simply doesn't (want to) realize that.
Jeremy Duncan
2nd May 2011, 10:36
So today I got back to the file -Vit- made and changed some settings, and now the final product randomizes clips so they look nice.
Here's a folder with the ex I made using the included c file and I also included the files you need to put in the clips folder (mp4box and some dll).
link to folder. The folder has the video that I randomized. (http://www.mediafire.com/?7u1son3i5a4fwb7)
Here's the original source clip: link: Red Riding Hood trailer clip (http://www.mediafire.com/?7bba5kc82wcmio5)
here's the modified c code in case you don't want to dl the folder:
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
// Mix actions (see below)
const int SHUFFLE = 0;
const int USER_CONTROL = 1;
// Output actions (see below)
const int MAKE_MP4 = 0;
const int MAKE_AVS = 1;
// Choose mix action
// - SHUFFLE: Shuffle clips randomly but with a fixed order selected by 'shuffleorder' below
// - USER_CONTROL: Type in special values for complete control over the mix using "boolean math" (spoken excitedly with emphasis, like an ad)
int mixaction = SHUFFLE;
// Choose output action
// - MAKE_MP4: Use mp4box to make a single "mix.mp4" from the shuffle (need mp4box.exe & js32.dll in the project folder)
// - MAKE_AVS: Create a "mix.avs" avisynth file that you can play or serve to another app or whatever
// Assumes there are 27 clips in "C:\Clips\" called "1.mp4", "2.mp4", etc.
int outputaction = MAKE_MP4;
// Choose fixed order for random shuffle (doesn't affect USER_CONTROL mode)
unsigned int shuffleorder = 123456987654;
// Values for the absolutely vital, patented "boolean math" used in USER_CONTROL mode (wow!)
int booleans[25] = { 2, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25 };
// Init playlist array
int play[25];
int x, y, t;
for (x = 0; x < 25; x++)
{
play[x] = x + 2;
}
if (mixaction == SHUFFLE)
{
// Fisher-Yates shuffle (done properly) of playlist with specific seed
srand(shuffleorder);
for (x=4; x<25; x++)
{
y = rand() % (x+1);
t = play[y];
play[y] = play[x];
play[x] = t;
}
}
else if (mixaction == USER_CONTROL)
{
// User control mode, do some complex "boolean math" to give complete control over the mix order (oooh!)
for (x = 0; x < 25; x++)
{
if ((play[x] >= booleans[x]) || (play[x] <= booleans[x]) || (play[x] = booleans[x])) // [I know, I know, quite deliberate...]
{
play[x] = booleans[x];
}
else
{
play[x] = play[x];
}
}
}
if (outputaction == MAKE_MP4)
{
char catcmd[2048]; // Make sure this is big enough for command
int index = 0;
index += sprintf(&catcmd[index], "mp4box.exe -cat \"C:\\Clips\\1.mp4\"");
for (x = 0; x < 25; x++)
{
index += sprintf(&catcmd[index], " -cat \"C:\\Clips\\%d.mp4\"", play[x]);
}
sprintf(&catcmd[index], " -cat \"C:\\Clips\\27.mp4\" mix.mp4");
system( catcmd );
system( "mix.mp4" );
}
else if (outputaction == MAKE_AVS)
{
FILE* file = fopen("mix.avs", "w");
fprintf(file, "DirectShowSource(\"C:\\Clips\\1.mp4\", audio=false, 23.976) + \\\n");
for (x = 0; x < 25; x++)
{
fprintf( file, "DirectShowSource(\"C:\\Clips\\%d.mp4\", audio=false, 23.976) + \\\n", play[x]);
}
fprintf(file, "DirectShowSource(\"C:\\Clips\\27.mp4\", audio=false, 23.976)\n");
fclose( file );
}
return 0;
}
Now if only I could use any number of clips this might be plugin worthy to release to the masses.
:helpful:
Oh God, the nightmare continues...
[...]
// Fisher-Yates shuffle (done properly) of playlist with specific seed
srand(shuffleorder);
for (x=4; x<25; x++)
{
y = rand() % (x+1);
t = play[y];
play[y] = play[x];
play[x] = t;
}
[...]
Now it isn't done properly :p
setarip_old
2nd May 2011, 22:08
@Jeremy Duncan
Hi!Now if only I could use any number of clips this might be plugin worthy to release to the masses.Forgive me for saying so, but I interpret this as little more than a one-off self-serving classroom exercise and, therefore, find it hard to believe it's something for "the masses".
By all means, correct me (with factual information) if you believe I'm mistaken...
Jeremy Duncan
3rd May 2011, 01:22
setarip_old,
After I posted that comment and logged out I realized that comment was wrong. It's wrong because I don't want to randomize the entire movie, or show from start to finish, because then the story is too disjointed.
Say there is 500 or so scenes in a movie or show, I want to break 500 up into 20 sections, each section consists of 27 scenes.
The beginning and ending scenes of each section is not random, but the 25 scenes within a section are randomized. So the beginning and ending section are where they should be in the movie.
This way the video doesn't disjoint the story too much.
I have no idea on how to do this though. :)
setarip_old
3rd May 2011, 03:05
@Jeremy Duncan
Based on your "response" to me, I can only believe that you haven't read my post. Based on this, I'll leave you to your own devices...
Jeremy Duncan
3rd May 2011, 15:55
Your reply was a interpretation. But it was interpreting old news that was no longer relavent.
I think I have a solution to my problem of how to randomize only 27 scenes from a 500 scene movie.
Put 27 scenes in a folder, then encode it to randomize it, then delete the contents of the folder after saving the mp4 file somewhere else, then starting over again either in the same folder or in a different folder until all 500 scenes in the movies are put through the process.
The hard part is trimming out all the scenes of the movie, even with a trim file listing all the scenes each scene will need to be taken from the source individually, according to Gavino. :eek:
Jeremy, I think you should give up on computer programming, really. Your lack of logical thinking and inability to abstract real world problems to mathematical scenarios prevent you from being capable to transform even simplest tasks to machine driven algorithms.
I do believe you have other great abilities (arts, social skills...) but clearly not the talent for programming, sorry.
TheRyuu
4th May 2011, 11:22
I still don't understand the point of doing this in C.
Please remind me.
It's like you're picking the hardest possible way to do it. Either that or you're just trolling everyone.
Groucho2004
4th May 2011, 11:48
I still don't understand the point of doing this in C.
Please remind me.
It's like you're picking the hardest possible way to do it. Either that or you're just trolling everyone.
I guess setarip_old nailed it:
Forgive me for saying so, but I interpret this as little more than a one-off self-serving classroom exercise
That, and a complete lack of understanding the differences between plain C programs and Avisynth plugins.
Jeremy Duncan
4th May 2011, 19:37
kypec,
I have nothing to say. I will learn C and then C++ and I am reading Neuron2's guide on how to build a plugin but after that what can I say?
I'm not speculating because code isn't easy to make assumptions on, it has to work and then it has to do what you want, in that order. In order to get it to where it does what I want I need a crude working sw that can be upgraded to do what I want.
Somebody below your post asked why not use some other language? Because I am not past leaning C yet.
I'm in no rush, my estimated time to finish project is unknown.
The Big problem I need to fix is how to generate avs scripts for my list of trims that show all the scene changes in a movie, there will be hundreds. Just getting the folder filled with these source clips will be difficult.
I may have to write a program that has a template for a avs file and I just copy and paste the text trim list into the program and it generates a avs file for each trim in the list.
I am reading Neuron2's guide on how to build a plugin I don't know what you are referring to here, as I have never written any such guide. Maybe you refer to BenRG's original site mirrored at my site? If so, be aware it is somewhat out-of-date and you may be better off following this thread:
http://forum.doom9.org/showthread.php?t=48261
This will also be handy:
http://avisynth.org/mediawiki/Filter_SDK/Compiling_instructions
Jeremy Duncan
4th May 2011, 21:06
Plan deleted and posted below.
To neuron2, I will quote you what I am learning:
How it works
Here's a line-by-line breakdown of Invert.cpp.
#include "avisynth.h"
This header declares all the classes and miscellaneous constants that you might need when writing a plugin. All external plugins should #include it.
External plugins do not link with avisynth.dll, so they can't directly access functions that are defined in the main Avisynth source code. Therefore, every important function in avisynth.h is either defined inline or declared as virtual. The virtual functions act as callbacks for external DLLs.
class Invert : public GenericVideoFilter {
An Avisynth filter is simply a C++ class implementing the IClip interface. IClip has four pure virtual methods: GetVideoInfo, GetFrame, GetParity, and GetAudio.
The class GenericVideoFilter is a simple do-nothing filter defined in avisynth.h. It derives from IClip and implements all four methods. Most filters can inherit from GenericVideoFilter rather than directly from IClip; this saves you from having to implement methods that you don't care about, like GetAudio.
Invert(PClip _child) : GenericVideoFilter(_child) {}
A PClip is a "smart pointer" to an IClip. It maintains a reference count on the IClip object and automagically deletes it when the last PClip referencing it goes away. For obvious reasons, you should always use PClip rather than IClip* to refer to clips.
Like a genuine pointer, a PClip is only four bytes long, so you can pass it around by value. Also like a pointer, a PClip can be assigned a null value (0), which is often useful as a sentinel. Unlike a pointer, PClip is initialized to 0 by default.
You'll need to make sure your class doesn't contain any circular PClip references, or any PClips sitting in dynamically allocated memory that you forget to delete. Other than that, you don't have to worry about the reference-counting machinery.
Avisynth filters have a standardized output channel via IClip, but (unlike VirtualDub filters) no standardized input channel. Each filter is responsible for obtaining its own source material -- usually (as in this case) from another clip, but sometimes from several different clips, or from a file.
GenericVideoFilter has a single constructor taking a single clip, which it then simply passes through to its output. We will override the GetFrame method to do something more useful, while leaving the other three methods as-is to pass through aspects of the clip that we don't need to change.
PVideoFrame Invert::GetFrame(int n, IScriptEnvironment* env) {
This method is called to make our filter produce frame n of its output. The second argument, env, is for our purposes simply a callback suite. It is actually implemented in Avisynth by a class called ScriptEnvironment. One instance of this class is created for each opened AVS script, so there may sometimes be several instances active at once. It is important that the callback functions be called through the proper instance. A particular instance of your class will only be used in one ScriptEnvironment, but different instances might be used in different ScriptEnvironments.
This method returns a PVideoFrame, which is a smart pointer like PClip.
PVideoFrame src = child->GetFrame(n, env);
"child" is a protected member of GenericVideoFilter, of type PClip. It contains the clip that was passed to the constructor. For our filter to produce frame n we need the corresponding frame of the input. If you need a different frame from the input, all you have to do is pass a different frame number to child->GetFrame.
GetFrame calls are usually intercepted by Avisynth's internal caching code, so the frame request may never actually reach the child filter.
PVideoFrame dst = env->NewVideoFrame(vi);
The NewVideoFrame callback allocates space for a video frame of the supplied size. (In this case it will hold our filter's output.) The frame buffer is uninitialized raw memory (except that in the debug build it gets filled with the repeating byte pattern 0A 11 0C A7 ED, which is easy to recognize because it looks like "ALLOCATED").
"vi" is another protected member of GenericVideoFilter (the only other member, actually). It is a struct of type VideoInfo, which contains information about the clip (like frame size, frame rate, pixel format, audio sample rate, etc.). NewVideoFrame uses the information in this struct to return a frame buffer of the appropriate size.
Frame buffers are reused once all the PVideoFrame references to them go away. So usually NewVideoFrame won't actually need to allocate any memory from the heap.
const unsigned char* srcp = src->GetReadPtr();
unsigned char* dstp = dst->GetWritePtr();
All frame buffers are readable, but not all are writable.
The rule about writability is this: A buffer is writable if and only if there is exactly one PVideoFrame pointing to it. In other words, you can only write to a buffer if no one else might be reading it. This rule guarantees that as long as you hold on to a PVideoFrame and don't write to it yourself, that frame will remain unchanged. The only drawback is that you can't have two PVideoFrames pointing to a writable buffer. This can sometimes be an inconvenience, as I'll explain later.
Any buffer you get from NewVideoFrame is guaranteed to be writable (as long as you only assign it to one PVideoFrame!). Our filter's dst came from NewVideoFrame, so we can safely call dst->GetWritePtr(). However, frames you get from other clips via GetFrame may not be writable, in which case GetWritePtr() will return a null pointer.
There is an IsWritable() method which you can call to find out if a buffer is writable or not, and there's a MakeWritable callback (described below) to ensure that it is.
const int src_pitch = src->GetPitch();
const int dst_pitch = dst->GetPitch();
Just as in VirtualDub, the "pitch" of a frame buffer is the offset (in bytes) from the beginning of one scan line to the beginning of the next. The source and destination buffers won't necessarily have the same pitch.
Buffers created by NewVideoFrame are always quadword (8-byte) aligned and always have a pitch that is a multiple of 8.
const int row_size = dst->GetRowSize();
The row size is the length of each row in bytes (not pixels). It's usually equal to the pitch or slightly less, but it may be significantly less if the frame in question has been through Crop.
Since our source and destination frames have the same width and pixel format, they will always have the same row size. Thus I only need one row_size variable, and I could just as well have called src->GetRowSize().
const int height = dst->GetHeight();
The height is the height. (In pixels.) Again, for our filter this is the same for the source and the destination.
for (int y = 0; y < height; y++) {
for (int x = 0; x < row_size; x++)
dstp[x] = srcp[x] ^ 255;
srcp += src_pitch;
dstp += dst_pitch;
}
This is the code that does the actual work. The "srcp += src_pitch; dstp += dst_pitch;" idiom is a useful way of dealing with potentially differing pitches without too much grief.
return dst;
GetFrame returns the newly-created frame. Our own references to this frame and to the source frame will go away with the src and dst variables. Our caller will become sole owner of the destination frame (which therefore will still be writable), and the source frame will be retained in the cache and eventually recycled. All through the magic of C++ classes.
AVSValue __cdecl Create_Invert(AVSValue args, void* user_data, IScriptEnvironment* env) {
In order to use our new filter, we need a scripting-language function which creates an instance of it. This is that function.
Script functions written in C++ take three arguments. args contains all the arguments passed to the function by the script. user_data contains the void pointer which you passed to AddFunction (see below). Usually you won't need this. env contains the same IScriptEnvironment pointer that will later be passed to GetFrame.
AVSValue is a variant type which can hold any one of the following: a boolean value (true/false); an integer; a floating-point number; a string; a video clip (PClip); an array of AVSValues; or nothing ("undefined").
You can test which one it is with the methods IsBool(), IsInt(), IsFloat(), IsString(), IsClip(), IsArray(), and Defined() (which returns true if the AVSValue is not "undefined").
You can get the value with AsBool(), AsInt(), etc.
For arrays, you can use the ArraySize() method to get the number of elements, and [] indexing to get the elements themselves. For convenience, IsFloat() and AsFloat() will work with integers also. But boolean values are not treated as numeric (unlike C).
The name "Create_Invert" is arbitrary. This function will actually be known as "Invert" in scripts, because that's the name we pass to AddFunction below.
return new Invert(args[0].AsClip());
The args argument passed to a script function will always be an array. The return value should be any one of the other types (never an array).
The types of the values in the args array are guaranteed to match one of the function signatures that you pass to AddFunction, just as in VirtualDub. Therefore, there's no need to worry about IsClip here.
Create_Invert simply creates and returns a filter instance; it is automatically converted to an AVSValue via the constructor AVSValue(IClip*).
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit(IScriptEnvironment* env) {
This is the only function which gets exported from the DLL. It is called by the script function LoadPlugin the first time this plugin is loaded in a particular script. If several scripts are open at once and more than one of them loads this plugin, AvisynthPluginInit may be called more than once with different IScriptEnvironments. Therefore:
• You should not save the env parameter in a global variable.
• If you need to initialize any static data, you should do it in DLLMain, not in this function.
The main purpose of the AvisynthPluginInit function is to call env->AddFunction.
env->AddFunction("Invert", "c", Create_Invert, 0);
As promised, we now call AddFunction to let Avisynth know of the existence of our filter. This function takes four arguments: the name of the new script function; the parameter-type string; the C++ function implementing the script function; and the user_data cookie.
The parameter-type string is similar to the corresponding entity in VirtualDub, except that:
• No return type is given. Function return values are not type-checked; you can return anything you like.
• There are more types: along with int and string you can specify bool, float, and 'clip.
• You can follow any type with '*' or '+' to indicate "zero or more" or "one or more" respectively. In this case all the matching arguments will be gathered into a sub-array.
For example, if your type string is "is+f", then the integer argument will be args[0], the string arguments will be args[1][0], args[1][1], etc.
There will be args 1; Array Size () of them - and the "float" argument will be args 2.
• '.' matches a single argument of any type. To match multiple arguments of any type, use ".*" or ".+".
• You can have named arguments, by specifying the name in [brackets] before the type.
Named arguments are also optional arguments; if the user omits them, they will be of the undefined type instead of the type you specify.
For convenience, AVSValue offers a set of As...() functions which take default values. See avisynth.h.
return "`Invert' sample plugin";
The return value of AvisynthPluginInit is a string which can contain any message you like, such as a notice identifying the version and author of the plugin. This string becomes the return value of LoadPlugin, and will almost always be ignored. You can also just return 0 if you prefer.
Thanks to that link I got SimpleSample from SI & Sh0dan. Link (http://avisynth.org/mediawiki/Filter_SDK/Simple_sample_1.0b). I will add this to my daily reading schedule. Thanks neuron2!
Make bat file and run it to get trim list, then auto copy and paste that list into graphical user interface and save results as bat files which are then auto executed, saving the clips into a folder.
This is yet another example why I think you should re-evaluate your true potential about programming in general.
GUI is not meant to serve as an interface for batch processing, this idea is nothing but utter silliness.
GUI has been invented for humans to pick and select parameters by simple clicking.
When I intend to process some list of inputs (Avisynth Trim commands for instance) in same way and repeat the process MANY times then I simply write a batch script either for pure DOS/Win shell or some other script language like VBS, Perl...
I believe this was my last post in this thread because you're clearly a hopeless case - not only you're not able to formulate your expectations/purpose of the program in a way that someone else would understand what is your input/what tools you plan to use/what is the expected output but your whole perception of programming and interaction between various parts in process chain is totally twisted and insane.
Good luck, anyway, you're sure gonna need it a lot! :p
Groucho2004
5th May 2011, 10:27
pure DOS/Win shell
What's that? Do you mean command line interface? Or are you actually running DOS?
What's that? Do you mean command line interface? Or are you actually running DOS?
Yeah, sorry about confusion. I meant standard cmd.exe environment in Windows of course a.k.a. console.
Jeremy Duncan
8th May 2011, 12:06
Here's my new plan. I'm posting this because kypec questioned my previous plan and since I revised my plan I will post it.
_____________________________________________________________________________________________________
1.) Scene change detection using mvtools2; completed.
2.) Randomization code semi-completed; need to learn the C language and finalize code.
3.) A code to take clips from the video source must be made; need to learn C language and use answer in Plan 2 to get clips.
4.) To automate this, making it user friendly. A video player might have to be built to get trim list, get clips, encode into randomized sequence, and then play the video after the sequence has been built.
These people like C sharp, so to do this step I may have to find the player and parts and see what I need to learn.
Unfortunately, in order to make this list I need to have solved steps 1 through 3 and plan #2, then I can ask for help and go to the next step, or leave my work and go away happy it at least works.
Plan 2.
How to get the clips from the video source:
1.) You simply need to read "Template A" into memory and find the point where you wish to insert.
Then in a loop read the line you wish to insert and write out a file consisting of three parts: A-before, then B-line, then A-after.
Groucho2004
8th May 2011, 17:36
To sum up:
while (JeremyDuncan->IsLearningC)
{
JeremyDuncan->PostingRandomDrivelOnDoom9;
}
Any ideas for a suitable break condition? :rolleyes:
To sum up:
while (JeremyDuncan->IsLearningC)
{
JeremyDuncan->PostingRandomDrivelOnDoom9;
}
Any ideas for a suitable break condition? :rolleyes: That's a one-liner. Try this:
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.