Streaming "proxy" converting video formats - iphone

This is related to my another question
Here I'd like to ask if it is in theory (according to video file formats and codecs, etc) possible to have such scenario:
1) Client on iPhone has a reference to video in flv format. It sends http request to converting "proxy" like http://convproxy.com?source=url_of_original_video.flv by just clicking such link in Safari
2) Converting proxy starts downloading that flv file and converting it to mp4 (which iphone understands) on the fly, returning converted portion as http response, so iPhone can immediately start playing it, before entire flv is downloaded and converted.
I was playing with ffmpeg trying to do such thing, and it indeed converts flv and produces mp4 file, however that mp4 file can not be played until convertion is finished or ffmpeg is stopped. If I just kill ffmpeg process the mp4 file can not be played. If I let it finish or press ctrl-c to stop it, the part that was downloaded and converted can be played. Seems like ffmpeg does some job after it receives stop signal. Is that a necessary part of mp4 format or it can be done differently? I see that iPhone can stream video, by starting playing before the entire file is downloaded to it, so in general it seems like possible scenario for me.
I short words, I can convert flv file to mp4 file, and the question is if I can convert flv stream to mp4 stream.

According to wikipedia, the MP4 container format requires a separate "hint track" to enable streaming. I assume ffmpeg writes this at the end of the conversion. If the iPhone OS requires this track to stream, I don't see a way to stream live video outside of using a different format and having a custom decoder on the iPhone side similar to how the Orb client for iPhone does it.

Related

AVPlayer, Play a local file URL that is currently being written to?

I have been trying to use a custom AVPlayerItem that lets me copy the currently playing media to file after it has been downloaded while it is streaming into the AVPlayer, essentially letting me cache the displayed video while showing the video as soon as possible.
Unfortunately, my application sometimes needs to download mp4 files from a server (that I don't control) that is giving the mime type as image/gif although the downloaded file IS an mp4 file. Because of this, my AVPlayer is not "streaming" in the video as it's downloaded, and only shows it once the file is completely downloaded and it realizes the file really is an MP4.
My thought is now to just download the file directly to a local file with a .mp4 extension that a standard AVPlayerItem can stream in, and write to this file while reading from it with the AVPlayerItem. Is this possible? Will the AVPlayerItem pause when it is still downloading/buffering the incomplete data or will it just produce an error without displaying anything? Is there a better way I can be doing this?

how to save stream as mp4 and play it?

I need to play a live stream of my computer screen with a play that knows only to play MP4 files
any ideas for how to save the stream to MP4 file and play is in the player ?
VLC is the only tool you need to capture your screen and save it to MP4 file. Then you can play it wherever you want.
Everything you want to do is well described here: http://www.howtogeek.com/120202/how-to-record-your-desktop-to-a-file-or-stream-it-over-the-internet-with-vlc/
You can also directly capture your screen and immediately stream it via multi/unicast stream.
Works great both on Nix and Win platforms.

How to do on the fly transcoding for webapp?

I have a library of videos (in .avi format). I'd like to make a webapp where I could watch these videos youtube-style, but without having to have all of them converted to flv format all the time -- so, basically, I want use the app to choose one to play, and transcode it on the fly. I'd also like to be able to pause, seek, etc.
Is this possible? If so, what would the overview of the process be? I know ffmpeg can be used to convert avi to flv, but I'm not sure about the rest of the process. Would I create one thread that start the transcoding, and then another which starts playing the output file as it gets transcoded? Or would that cause problems with playback since it would only be a partial file? Is there a better way of doing this?
For reference, I'll be using grails to write the webapp.
On the fly transcoding use vlc or ffmpeg with red5

Playing .flv files on iphone

I have a webservice returning .flv file, it has to be played in iphone application, how do i play a .flv (flash file) in iphone?
Does anyone has faced this scenario? Programmatically is it possible to convert to some format and play in iphone?
Thanks.
IPhone doesn't and judging by the Apple official statements won't ever (or at least in the forseeable future) support flash content.
Converting the content to another format on the server side should be easy to do and would allow content playback on an iDevice.
SInce the video is probably already h.264 encoded inside the FLV container, you may want to try FLV Extract on the server to avoid recompression:
http://www.videohelp.com/tools/FLV_Extract
Basically you just need to run it once for each of the videos on the server and keep the results around.
I would recommend setting up your webservice to use something like ffmpeg ( http://www.ffmpeg.org/ ) to convert the .flv file to an mp4 file which can be played directly from the iPhone's web browser.
Pioto and Josaih are on the right track in suggesting that you should convert the video server-side using a tool like FFMpeg. As far as I know there is zero support for flv in any part of iOS, so you'd be unable to transcode it locally. Even if you could, it would make your users angry, since transcoding is a resource-intensive process that would kill their battery life and take a significant amount of time.
So, your solution is to transcode your videos to h.264 server-side. However, I'd caution against transcoding from flv->h.264 if there are any other options available. If you have the original, uncompressed (or at least less-compressed) source video available, you'll get higher-quality video by transcoding that to h.264. Each time lossy compression (eg, squeeze or h.264) is used on a file, you lose some information and quality. If you've ever seen a 3rd or 4th generation copy of a VHS tape, you can understand what I'm getting at.
Once you have a h.264 formatted video, you can play it on iOS. Not sure about the exact details of this.
You may be able to use ffmpeg or something on your server to transcode it to H.264. I'm not so sure you would really want to do that transcoding on the phone. Given Apple's current stance on Flash, this is probably your best option.
For FLV files, what I do is I upload them on Google Drive and watch them from Google Drive app.

encoding H.264 video (or similar) on the iPhone directly?

What's the best way to encode video (with audio) on the iPhone? It looks like QTKit isn't available... so I might have to link with ffmpeg, but ffmpeg doesn't look like it encodes H.264 (judging from their home page.)
If it is possible, I'm also curious how fast I can expect it to perform on the ARM. I imagine it might take minutes to encode a 20sec movie.
Both ffmpeg and mencoder will encode H2.264 videos when combined with x264, but I'd imagine getting it all running iPhone would be an absolute nightmare, let alone the performance of it once you've got it running.
A while ago I wrote an AVI encoder for the iPhone that used raw file I/O. I just started work on a QuickTime encoder that encodes BMP data into a quicktime container. If it is H.264 you want to encode, I would try making a server that uses QTKit and having your app connect to that for conversion.