Figure out possible ways to save mp4 streamed from internet - save

Summary:
While a video is streaming in the internet browser, packets of mp4 files are being downloaded.
I would like to write some code that saves the packets into one file so the video is preserved after it is done streaming.
I think this could be done by taking the packets in as byte files, removing how ever many bytes the addressing header at the front is made out of, and then concatenating the rest, but I will be the first to admit that I have never done anything like this before and don't really know what I am doing.
If anyone out there has experience with with this kind of thing, I am not looking for much, just a few words to point me in the right direction, or at least keep me from going too far in the wrong direction. I am really just coming at this project with half a CS degree and some notions about what to google right now.
Specific Questions:
Do you know how I can access the data packs being downloaded from the internet? For example, if I wanted to make a script that grabbed each of the mp4 data packs as they came in, what kind of command would I use to access them?
Do you know what would be the best way to save the video file? Should I access the data packs as they come in? or should I access them later, as they have been strung together by the media player? Is the second part even possible or would the data be protected by that time?
If you don't have answers to these questions, are you able to give me a reference to a place the does? I haven't been able to find this subject on stack. Even some good keywords to search for would be useful.
Thanks for taking the time to read,
-Coder 357
TLDR: Trying to make code or script to save the mp4 packets into video files as they are streamed.
Progress So Far:
I suppose all I have done is press f12 and open up the network activity section of the internet page, streaming the video I want to capture. I know that I am rapidly fetching mp4 files in the kb and mb size range. That is what lead me to my conclusion that I will likely need to string these mp4 files together into one file, after removing any extra bits and bytes at the front and end.
That being said, I don't have an understanding of how my media player holds the data, so there may be a much more convenient way to do this that I am not seeing.
Goal:
My best case expectation for the project is to have a program or script which can be run from the command line and will then combined mp4 data packets, from a given website, into a single video file.

Related

How to build a simple video streaming server?

I am a newbie in video streaming and I just build a sample website which plays videos. Here i just give the video file location to the video tag in html5. I just noticed that in youtube the video tag contains the blob url and had a look into this. I found that the video data comes in segments and came across a term called pseudo streaming. Whereas it seems likes the website that i build downloads the whole file and plays the video. I am not trying to do any live streaming, just trying to stream local videos. I thought maybe the way video data is received in segments is done by a video streaming server. I came across RED5 open source streaming server, but most of the examples that is given is for live streaming which I am not experimenting on. Its been few days and I am not sure whether i am on the right track
The segmented approach you refer to is to support Adaptive Bit Rate streaming - ABR.
ABR allows the client device or player download the video in chunks, e.g 10 second chunks, and select the next chunk from the bit rate most appropriate to the current network conditions. See here for an example:
https://stackoverflow.com/a/42365034/334402
For your existing site, so long as your server supports range requests then you probably are not actually downloading the whole video. With Range Requests, the browser or player will request just part of the file at a time so it can start playback before the whole file is downloaded.
For MP4 files, it is worth noting that you need to have the header information, which is contained in a 'block' or 'atom' called MOOV atom, at the start of the file rather than the end - it is at the end for regular MP4 files. There are a number of tools which will allow you move it to the start - e.g.:
http://multimedia.cx/eggs/improving-qt-faststart/
You are definitely on the right track with your investigations - video hosting and streaming is a specialist area so it is generally easier to leverage existing streaming technologies and services rather than to build them your self. Some good places to look to get a feel for open source solutions:
https://gstreamer.freedesktop.org
http://www.videolan.org/vlc/streaming.html

How to play wav file with 8Kbps bit rate in iOS application?

I develop an iOS application where i should call web service and return audio file ( as byte array ) then play it to user .
I have problem with audio file format as it has 8 Kbps bit rate and no player inside app can play it. when I convert it to any other bit rate for example (13 Kbps) from server side to test it works properly . However i have a huge number of file where converting them manually is impossible . is there any way to convert file inside iOS app code ?
To address your comment about converting the files manually: Is it a plausible solution for you to do it automatically, server side? If so, you probably have a few options.
One would be to install Audacity, which handles all of these bit rates, and use the Chains feature for batch processing. If it's a one-off conversion you could initiate it manually, otherwise you may need to find a way of scripting the process (if new files come in from an external source, that is).
As for playing these files in iOS, have you considered embedding libpd (just one example of many, but one that you can get up and running in minutes)? It has a fairly open approach to file playback, and may handle these file formats. If you send me an example I can test right away!

Capture, encode then stream video from an iPhone to a server

I've got experience with building iOS apps but don't have experience with video. I want to build an iPhone app that streams real time video to a server. Once on the server I will deliver that video to consumers in real time.
I've read quite a bit of material. Can someone let me know if the following is correct and fill in the blanks for me.
To record video on the iPhone I should use the AVFoundation classes. When using the AVCaptureSession the delegate method captureOutput:didOutputSampleBuffer::fromConnection I can get access to each frame of video. Now that I have the video frame I need to encode the frame
I know that the Foundation classes only offer H264 encoding via AVAssetWriter and not via a class that easily supports streaming to a web server. Therefore, I am left with writing the video to a file.
I've read other posts that say they can use two AssetWritters to write 10 second blocks then NSStream those 10 second blocks to the server. Can someone explain how to code the use of two AVAssetWriters working together to achieve this. If anyone has code could they please share.
You are correct that the only way to use the hardware encoders on the iPhone is by using the AVAssetWriter class to write the encoded video to a file. Unfortunately the AVAssetWriter does not write the moov atom to the file (which is required to decode the encoded video) until the file is closed.
Thus one way to stream the encoded video to a server would be to write 10 second blocks of video to a file, close it, and send that file to the server. I have read that this method can be used with no gaps in playback caused by the closing and opening of files, though I have not attempted this myself.
I found another way to stream video here.
This example opens 2 AVAssetWriters. Then on the first frame it writes to two files but immediately closes one of the files so the moov atom gets written. Then with the moov atom data the second file can be used as a pipe to get a stream of encoded video data. This example only works for sending video data but it is very clean and easy to understand code that helped me figure out how to deal with many issues with video on the iPhone.

Watch video in the time they are uploaded

It is possible to implement a feature that allows users to watch videos as they are uploaded to server by others. Is html 5 suitable for this task? But flash? Are there any read to go solutions, don't want to reinvent the wheel. The application will be hosted on a dedicated server.
Thanks.
Of course it is possible, the data is there isnt it?
However it will be very hard to implement.
Also I am not so into python and I am not aware of a library or service suiting your requirements, but I can cover the basics of video streaming.
I assume you are talking about video files that are uploaded and not streams. Because, for that, there are obviously thousands of solutions out there...
In the most simple case the video being uploaded is already ready to be served to your clients and has a so called "faststart atom". They are container format specific and there are sometimes a bunch of them. The most common is the moov-atom. It contains a lot of data and is very complex, however in our use case, in a nutshell, it holds the data that enables the client to begin playing the video right away using the data available from the beginning.
You need that if you have progressive download videos (youtube...), meaning where a file is served from a Webserver. You obviously have not downloaded the full file and the player already can start playing.
If the fastastart atom was not present, that would not be possible.
Sometimes it is, but the player for example cannot display a progress bar, because it doesnt know how long the file is.
Having that covered the file could be uploaded. You will need an upload solution that writes the data directly to a buffer or a file. (file will be easier...).
This is almost always the case, for example PHP creates a file in the tmp_dir. You can also specify it if you want to find the video while its being uploaded.
Well, now you can start reading that file byte by byte and print that data to a connection to another client. Just be sure not to go ahead of what has already been recieved and written. You would probaby initiate your upload with a metadata set in memory that holds the current recieved byte position and location of the file.
Anyone who requests the file after the uploaded has started can just recieve the entire file, or if the upload is not yet finished, get it from your application.
You will have to throttle the data delivery or pause it when the data becomes short. This will appear to the client almost as a "slow connection". However you will have to echo some data from time to time to prevent the connection from closing. But if your upload doesnt stall, and why shoud it?, that shouldnt be a problem.
Now if you want to have someting like on the fly transcoding of various input formats into your desired output format, things get interesting.
AFAIK ffmpeg has neat apis which lets you directly deal with datasterams.
Also handbrake is a very good tool, however you would need to take the long road using external executeables.
I am not really aware of your requirements, however if your clients are already tuned in, for example on a red 5 streaming server, feeding data into a stream should also work fine.
Yes, take a look at Qik, http://qik.com/
"Instant Video Sharing ... Videos can be viewed live (right as they are being recorded) or anytime later."
Qik provides developer APIs, including ones like these:
qik.stream.subscribe_public_recent -- Subscribe to the videos (live and recorded)
qik.user.following -- Provides the list of people the user is following
qik.stream.public_info -- Get public information for a specific video
It is most certainly to do this, but it won't be trivial. And no, I don't think that you will find an "out of the box" solution that will require little effort on your behalf.
You say you want to let:
users watch videos as they are uploaded to server by others
Well, this could be interpreted two different ways:
Do you mean that you don't want a user to have to refresh the page before seeing new videos that other users have just finished uploading?
Or do you mean that you want one user to be able to watch a partially uploaded video (aka another user is still in the process of uploading it and right now the server only contains a partial upload of the video)?
Implementing #1 wouldn't be hard at all whatsoever. You would just need an AJAX script to check for newly uploaded videos, and those videos could then be served to the user in whatever way you choose. HTML5 vs. Flash isn't really a consideration here.
The second scenario, on the other hand, would require quite a bit of effort. I am guessing that HTML5 might not be mature enough to handle this type of situation. If you are not looking
to reinvent the wheel and don't have a lot of time to dedicate to this feature than I would say that you would be out of luck. You may be able to use ffmpeg to parse partial video files and feed them to a Flash player, but I would think of this as a large task.

How to play an encrypted media file-IOS-iPhone?

i'm writing an app to play some media encrypted files
Normally,we can decrypt these files and play it.But i don't want anybody can get this decrypt file when app is playing this file.
Or i want protect these file.
I'm researching but i don't find a solution.
Can anyone suggest to me a solution?Can anyway to protect media files without encryption?
Thanks so much.
Regards
The short answer: You can't stop copying, no matter how hard you try.
The long answer: This problem has been around since the dawn of Internet distribution. Nobody has solved it effectively yet. The problem is that if a user jailbreaks a device they can do anything that the hardware is capable of. This includes recording directly from the audio buffer into a file, making it a simple process to capture your file while it is playing and dump the contents into another file. Therefore, if you can play it, you can copy it. The only solution that I can see working is to build your own hardware that doesn't allow external access to the audio buffer, but that is impossible for 99% of people and impractical for 100%.
The compromise: The best you can do is make it more trouble than it is worth for the user. If you can decrypt into a memory buffer then it will be an annoying task to get the data, and most people will probably not put the effort into it.

Resources