View Full Version : I'm trying to make a "C" script to play clips in random order.
-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-2025, vBulletin Solutions Inc.