video is not running.I want to get the video using java - java

I had downloaded a .flv video of large size using Orbit downloader which cuts the file into eight parts and then joins them back. After downloading , I have found that the video is not running and stops after some time. I want to extract all the video and save it in another file using java program.Can anyone help me , please ???

You need to understand FLV file format for this. Check out http://www.adobe.com/devnet/f4v.html.
Typically flv file contains header fields and some of those fields specify track length, if the file stops in between , your header fields are not storing the right values.

Related

Java - Get snippet from video of URL

Lets say I have this video url : http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4
and I need to download just a small playable snippet from this video (e.g. 00:24 - 00:30).
How should I do this in java? And I don't want to download the entire video and then cut it.
I already looked at the network tab of chrome and read the request and response headers but couldn't get much sense of it, except:
"Range:bytes=0-" in the request header
"Content-Length:5510872" in the response header
But I can't just choose any range because it would make the video not playable right?
So how does the browser know which range it should get if I click on 00:24?
assuming you're working with .mp4 containers,
the mp4 file format contains a hierarchical structure of 'boxes' (aka "atoms'). The magic for fast seeking lies in the moov atom which is why when encoding a video for web it's always best to optimize the structure of the file and relocate that to the front so that the browser has access to the metadata as the very first thing it downloads.
moov
Movie box which is the container for all metadata
Each moov has have a mvhd (Movie header box)
It can contains N trak box(es). Each trak box contains media specific meta data information Usually, it will have 2 tracks (video and audio)
More importantly, it contains sample information such as stsd, stts, stsz stsc, stco, etc...
stts - Time-To-Sample (stts) box.
This box contains the time of every frame (in a compact fashion). From here you can find the 'chunk' that contains the frame using the Sample-to-Chunk (stsc) atom. And finally the Chunk offset atom (stco) gives you the byte offset into the file.
Projects like MP4Parser or Xuggler can get you started on processing the MP4 container yourself (have samples on reading the underlying MP4 structure), but it's not a trivial undertaking - sadly there doesn't seem to be a comprehensive MP4 API toolkit for Java

Downloading video file by streaming a certain part of the video

An online link gives me back a video in my browser, that is then streamed. In my browser, I don't need to download the whole video to visualize it - I can skip to a certain part, visualize that part, and even stop watching before the end.
How can I, from the very same link, start to stream from a specific time onwards until another specific time, and each time save every frame I received to a video file?
I do know that I need to decode the data I get.
I also know that I need to somehow access the metadata of the video file.
However, I don't know how to deal with it in practice.
I tried out JCodec, but could not find how to deal with internet streams instead of opening files.
How can I properly stream parts of an online video, frame-by-frame, while also having access to metadata such as total video length, resolution, and FPS?
To answer the first parts of your question:
Trim videos with start offset and either end offset or duration (in seconds, percentages, etc.), e.g. http://res.cloudinary.com/demo/video/upload/so_6.5,eo_10/dog.mp4
Grab frames at desired timestamps along the original video, e.g. http://res.cloudinary.com/demo/video/upload/so_8.5/dog.jpg to save a JPEG-format frame at 8.5 seconds from the start of the video.

Getting metadata of an APNG image

I am trying to get the metadata of an apng image at the moment. I have
been able to get different frames from one apng file flawlessly and i am using PNGJ (a really great Standalone Java library for reading and writing PNG images), but I
am not able to get the different info that is stored against every
apng frame like delay of every frame.
I am at the moment just able to get the simple png image info that is stored in the header part by using
PngReader pngr = FileHelper.createPngReader(File);
pngr.imgInfo;
But I don't know how to have the information stored against the fcTL chunk. How can I do that?
You omitted the information that you are using the PNGJ library. As I mentioned in the other answer, this library does not parse APGN chunks (fcTL, fdAT). It loads them (you can inspect them in the ChunksList property) but they will be instatiated as "UNKNOWN" chunks, hence the binary data will be left in raw form. If you want to look inside the content of the fcTL chunks, you'd either parse the binary yourself, or implement youself the logic for that chunk type and register it in the reader (here's an example for a custom chunk).
Look at how you're currently reading 4-bytes integer 'seq' from fdAT.
You can read information from fcTL the same way.
Just keep in mind that some info is stored in fcTL as 4 bytes, some as 2 bytes, and some as 1 byte.

Streaming multiple FLV files over a Java servlet as a single file

I am trying to implement a Java servlet that runs on Tomcat, capable of streaming multiple FLV files to client browsers having JWPlayer. The catch is I have to stream multiple files one at a time and sometimes start streaming from the middle of the first clip and I need JWPlayer to think that the file duration is the duration of all the clips combined.
My servlet would work well if I merged all of the clips to one single FLV file, injected the metadata (using yamdi) and then streamed it. But this can be pretty time consuming. I've tried sending the player the meta information for the file that I stream from the middle first and then go ahead and stream it from the middle but this doesn't seem to work. I've tried fiddling with the duration parameter in the metadata to no avail.
I think that this is because I'm skipping tags when i start to stream from the middle of the clip. Would it be humanly possible to construct tags while processing the byte stream before the servlet sends it out?
You don't need the meta data, other than the initial FLV header and individual frame descriptions. As long as your FLV frames are correctly and atomically started and stopped, what you are doing seems very possible to me. (I had considered doing something similar, having already written an FLV parser.) Be sure not to send a Length header. ;) Two things might make all of this much easier to accomplish:
ensure you've encoded your video with smallish key frame interval. You won't be able to jump between clips at any finer of a resolution than this. Anything less that 1s is probably going to be problematic, much higher video rates.
pre-parse all your video files into segments. When the servlet is called,
send the FLV header
read and write whole segment files to the client
1- to switch videos, move to another group of segment files
Example that assumes you want to send each original file from the start:
send(FLV_HEADER)
i = 0
while(send file 1 condition == true)
send(file-1-segment i++)
i = 0
while(send file 2 condition == true)
send(file-2-segment i++)
(Alternatively you could map some indexes and use them to read frames from the middle of a file. Been there, done that.)

Change the volume of an audio file and save the file using java.sound.sampled

I want to change the volume of an audio file
and save the new file using java.sound.sampled.
I tried to use the mixer to create a source line
from the file given and a target line to the new file.
So that I can change the mixer settings to change the volume.
But the sound is being played to the system speaker.
Am I thinking along correct way or not?
Is there any other way to record a file from a line?
The code is available here
A solution I got is www.jsresources.org/examples/AmplitudeConverter.html.
But can the same be done within java.sound.sampled
without using external libraries.
To change the volume, if you don't use a "Control" (see the Java Sound Tutorials), there is the option of directly modifying the samples themselves.
In your innermost loop, convert the bytes in the innermost buffer into a sample (if it is WAV 16-bit encoding, then you need to put the two bytes together to make the single SHORT value), then multiply that value by a float that ranges from 0 to 1, where 0 is the quietest and 1 leaves the sound at full volume. Then take the result and break it back down into two bytes and pass it along.
Do you need the code to do this? There are several other posts here where folks convert from bytes to INTs or Float and back.
Hmmm. This question is pretty old. Well maybe my answer will help someone new to the same problem.

Categories

Resources