Jump to content

Can I interact with ffmpeg using java in a simple way

taurasnewx
Go to solution Solved by wanderingfool2,
5 hours ago, taurasnewx said:

can you clarify

Absolutely not...I refuse to clarify.

 

Anyways, to the non-sarcastic response.  Which bit would you like clarification on? [I've also done a slight overview below, but I am typing this quickly as I don't have a bunch of time now...I might come back to this later and fix it up]

 

An example of what I am running with my ffmpeg [explaining this in c# terms, there must be Java equivalents of Process but I can't bother looking into it right now]

Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.FileName = APP_LOCATION + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = String.Format(
	"-v quiet -i \"{0}\" -vf \"select = not(mod(n\\, 300)), scale=480:270\" -vsync vfr -an -frames:v 100 -c:v bmp -f image2pipe pipe:",
	_fileLocation
	);
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();

There is actually an amazingly lack of examples on the internet I find in regards to the image2pipe and pipe: parts...but effectively what the above command does is pipe the all of the images (every 300 frames...so in my case every 10 seconds, and only the first 100 results that match that) into standard out (as a bmp format).  [In my case, I essentially fit the entire cut segment into memory because it fits my usecase and I can't be bothered to spend more time writing correct buffers for just a quick one off project I was doing]

 

From there, I can just chop up the bytes from the standard output and make it into bitmaps...i.e. since it's bitmaps I know that it will be a fixed size, so I can chop up the memory into the bytes corresponding to each image and just process that (in my case I think it was 388854 bytes per image)...but it's easy to calculate as I could just change it to -frames:v 1 and then see how many bytes the standard out is.

 

And presto, you have the image from the video file

I want to makethings like a video player and editor using ffmpeg and java and Im a beginner at ffmpeg and know all the simple stuff in java(like variables, windows, and can make a basic 2D game in it where you kill things, get upgrades and play music) but cant find an up to date library to simply use ffmpeg in java (without any fancy commands or anything hard to understand).

I did see xuggle but I think thats very outdated(based on it not having any videos working).

Can someone help me please I dont know what to do.

Link to comment
Share on other sites

Link to post
Share on other sites

-> Moved to Programming

^^^^ That's my post ^^^^
<-- This is me --- That's your scrollbar -->
vvvv Who's there? vvvv

Link to comment
Share on other sites

Link to post
Share on other sites

The solution will all depend really...Windows vs Linux vs Cross compatibility.

 

What specifically are you looking to do in your project...editing might be a bit difficult with the ffmpeg library (for beginners)...or if you don't mind waiting for a delay (seriously, ffmpeg to pull a single frame halfway through a video takes 0.5 seconds on my computer...so you need to buffer)

 

You could always pipe the output into image files...that's what I did when I needed it for a project (but then again, lag and stuff didn't really bother me that much).

 

That way you can use "-image2 pipe:" command in ffmpeg to dump the frames to a standard out.  From there, you can break up the image.  Not sure how to do it specifically in Java (only did it in c# .net framework)

3735928559 - Beware of the dead beef

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, wanderingfool2 said:

The solution will all depend really...Windows vs Linux vs Cross compatibility.

 

What specifically are you looking to do in your project...editing might be a bit difficult with the ffmpeg library (for beginners)...or if you don't mind waiting for a delay (seriously, ffmpeg to pull a single frame halfway through a video takes 0.5 seconds on my computer...so you need to buffer)

 

You could always pipe the output into image files...that's what I did when I needed it for a project (but then again, lag and stuff didn't really bother me that much).

 

That way you can use "-image2 pipe:" command in ffmpeg to dump the frames to a standard out.  From there, you can break up the image.  Not sure how to do it specifically in Java (only did it in c# .net framework)

can you clarify

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, taurasnewx said:

can you clarify

Absolutely not...I refuse to clarify.

 

Anyways, to the non-sarcastic response.  Which bit would you like clarification on? [I've also done a slight overview below, but I am typing this quickly as I don't have a bunch of time now...I might come back to this later and fix it up]

 

An example of what I am running with my ffmpeg [explaining this in c# terms, there must be Java equivalents of Process but I can't bother looking into it right now]

Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.FileName = APP_LOCATION + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = String.Format(
	"-v quiet -i \"{0}\" -vf \"select = not(mod(n\\, 300)), scale=480:270\" -vsync vfr -an -frames:v 100 -c:v bmp -f image2pipe pipe:",
	_fileLocation
	);
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();

There is actually an amazingly lack of examples on the internet I find in regards to the image2pipe and pipe: parts...but effectively what the above command does is pipe the all of the images (every 300 frames...so in my case every 10 seconds, and only the first 100 results that match that) into standard out (as a bmp format).  [In my case, I essentially fit the entire cut segment into memory because it fits my usecase and I can't be bothered to spend more time writing correct buffers for just a quick one off project I was doing]

 

From there, I can just chop up the bytes from the standard output and make it into bitmaps...i.e. since it's bitmaps I know that it will be a fixed size, so I can chop up the memory into the bytes corresponding to each image and just process that (in my case I think it was 388854 bytes per image)...but it's easy to calculate as I could just change it to -frames:v 1 and then see how many bytes the standard out is.

 

And presto, you have the image from the video file

3735928559 - Beware of the dead beef

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, wanderingfool2 said:

Absolutely not...I refuse to clarify.

 

Anyways, to the non-sarcastic response.  Which bit would you like clarification on? [I've also done a slight overview below, but I am typing this quickly as I don't have a bunch of time now...I might come back to this later and fix it up]

 

An example of what I am running with my ffmpeg [explaining this in c# terms, there must be Java equivalents of Process but I can't bother looking into it right now]


Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.FileName = APP_LOCATION + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = String.Format(
	"-v quiet -i \"{0}\" -vf \"select = not(mod(n\\, 300)), scale=480:270\" -vsync vfr -an -frames:v 100 -c:v bmp -f image2pipe pipe:",
	_fileLocation
	);
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();

There is actually an amazingly lack of examples on the internet I find in regards to the image2pipe and pipe: parts...but effectively what the above command does is pipe the all of the images (every 300 frames...so in my case every 10 seconds, and only the first 100 results that match that) into standard out (as a bmp format).  [In my case, I essentially fit the entire cut segment into memory because it fits my usecase and I can't be bothered to spend more time writing correct buffers for just a quick one off project I was doing]

 

From there, I can just chop up the bytes from the standard output and make it into bitmaps...i.e. since it's bitmaps I know that it will be a fixed size, so I can chop up the memory into the bytes corresponding to each image and just process that (in my case I think it was 388854 bytes per image)...but it's easy to calculate as I could just change it to -frames:v 1 and then see how many bytes the standard out is.

 

And presto, you have the image from the video file

that explains enough of how it works, thanks for the answer

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×