iOS UIImagePickerController for Video URL Only - ios

I'm using the UIImagePickerController to select a video from the the device's camera roll. However, I'm not interested in viewing the video at this time; I want to save the URL (in Core Data) so that when the user chooses the name of the video from, for example, a pickerView, the video will load and play at that time.
My understanding (which may be wrong) is the UIImagePickerController makes a compressed copy into the sandbox and provides two different URLS (in the info dictionary). It is kind of a guess at this point, but what I think is:
UIImagePickerControllerMediaURL is the url that points to the original video; and
UIImagePickerControllerReferenceURL is the url that points to the copy.
Here are my questions:
a) Is my assumption correct as to what the two URLs point to, and can I count on the ReferenceURL to point to the selected video so long as it is on the device's camera roll?
and
b) Under the circumstances, is there any way to avoid the compression? From reading on SO, I'm thinking there may not be, but I haven't really seen any posts that really relate exactly to what I'm doing. The structure of my app is such that there could be a lot of these videos and users will not want to get rid of the original, so there is no point in having both the original and compressed version around.
All I'm interested in is a URL I can use to access the video in the camera roll. I will also have to get a thumbnail of it to store with the URL, but I think I see how to do that.
Any help on this will be greatly appreciated.

If you only want the URL to access the video, then you can use UIImagePickerControllerMediaURL this specifies the filesystem URL for the movie (if editing is enabled, this points to the edited/trimmed video).If you want the original video URL you can se UIImagePickerControllerReferenceURL this is the Assets Library URL for the original version of the video. (The truly selected item, without editing). You can, of course, establish controller.allowsEditing = NO to avoid user to edit the video, getting in UIImagePickerControllerMediaURL the URL of the original unedited video.
AFAIK there is no compression applied to the recorded/selected video by default, this only happens if you press the Share button and try to send the file over MMS, MobileMe, etc., just make sure you establish controller.videoQuality = UIImagePickerControllerQualityTypeHigh to get highest quality.

Related

Getting the size of a media item given a NSItemProvider?

I'm using a PHPickerViewController to allow the user to select a media item from their library. And the specific case of interest is when they select a video.
I get a callback on the PHPickerViewControllerDelegate delegate method:
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult])
And I'm using loadFileRepresentation to get the video from the NSItemProvider.
However, that call takes a substantial amount of time. And it may be all for nothing -- since I'm imposing a size limit on the videos that users can add to the app.
So, my question is: Is there a way to determine, quickly, the size of the media item that the user has selected? E.g., given the NSItemProvider?
You're looking in the wrong place. What you're starting with, even before you have an item provider, is a PHPickerResult. It gives you the asset identifier. From there you can obtain from the photo library the PHAsset and find out anything the photo library is willing to tell you. Size is an amorphous concept, but you can certainly get the video pixel dimensions and its duration instantly, which will tell you a lot.
Of course you'll need photo library read permission to go that route, which you don't need merely to save the video to a file.
On the other hand, since videos are huge, one might ask what you care about the size. The key thing to do with a video is not to obtain its entirety as a lump of data but to play it, and the photo library will let you do that instantly.
I would also try loadInPlaceFileRepresentation if possible, it will be much faster.

Play video using Data content without saving

My question is simple...
I have an array of bytes or actually a data of my video, and I want to play it.
Every library that I use, saves the Data & gets the path of saved Data as URL.
But I don't want to save the Data...
Kindly help me what to do to play a video using bytes or Data, without saving it.
but I don't want to save the Data
Yes, you do. You never want to play a video from data held in memory; it's way too big and will crash your app. And in fact the system isn't even set up to play video out of memory! It's set up to play video out of files.
So, as you obtain the data you save it, and in order to play it, you supply the file URL where you saved it. That's the right way.

Store data in video frames while capturing the video in iOS

How to store the data like time or latitude in video frames per second while capturing the video and retrieve this data back from the saved video in iOS?
Most video formats include video MetaData, describing the whole video at the asset level. When using AVAssetWriter, you can add MetaData items before writing to associate this with the output file. https://developer.apple.com/reference/avfoundation/avassetwriter#//apple_ref/occ/instp/AVAssetWriter/metadata
There are common keys (https://developer.apple.com/reference/avfoundation/1668870-av_foundation_metadata_key_const/1669056-common_metadata_keys) you can use to store the information if you like.
Note this is only at the file level, not per frame.
If you want to store information at a "frames per second" type time refernece then you could build a custom solution, interacting with the buffers "vended" by AVFoundation Recording locations in time domain with AVFoundation It's possible to then write your own custom storage for that information that's synchronised to the video file and you would need to read it back and process it yourself.
I don't believe there's a way to encapsulate that "per frame location info" within the actual video file itself (you could perhaps do a hack and repurpose a subtitles AVAssetTrack and write the info, then pull it off but not display it - this would be unpredictable when video was played on other devices however).
ADDITIONAL INFO
Following on from a comment a year after I wrote this, I did some more investigation. While you could use and abuse the subtitle track like suggested, a better solution is to use the AVAsset metadata type which is specifically for this. https://developer.apple.com/documentation/avfoundation/avmediatype/1390709-subtitle
There are many different AVAssetTrack types which allow you to time data to a point on a video including
Audio
closedCaption
depthData (BETA at time of edit)
metaData <- This is probably what you want
metaDataObject <- In combination with this one too
muxed
text
timecode
video

How can i get the size of dailymotion videos?

I want to save data traffic during the time that user is watching dailymotion video. Is anyone having an idea? Thanks in advance
This info is not available in the API. Note that the data used will depend on the video quality (1080px, 720px, 480px, etc), and that may vary from a user to another, depending on their device, bandwidth, etc. It is automatically chosen by the video player but the user can also decide to specify a quality.
You will see all available fields for a video object in the documentation at: https://developer.dailymotion.com/api#video-fields
Just make a getimagesize of the thumbnail_url !

How do I get a YouTube FLV URL?

Looking through the site, every question uses an outdated method. How do the YouTube FLV downloader websites/applications do it?
I am trying to do this in PHP but the theory or steps to do it will suffice, thanks.
As mentioned in other posts, you may want to look at our code in
youtube-dl (or in the code of the Firefox extension called
FlashVideoReplacer).
In the particular case of youtube-dl, the "real work" is done in the
subclasses of InformationExtractor and it hard to give a "stable" answer,
as the layout of such sites changes constantly.
There are some pieces of the information that are not dynamic, such as, for
instance, the uploader of the video, the title, the date of upload, and,
most importantly, the identifier of the video (a 11-character string).
For the dynamic parts, what can be said about such tools is that,
essentially, the URLs generated by such videos are dynamically generated and
you need to perform some back-and-forth communication with the server.
It is important to have in mind that what such sites can (and do) take into
consideration depend on a number of parameters, including: the cookies that
you have already received---as the case for HTML5 videos, your
geolocation---for regional control, your age--for "strong" material, your
language/locale---for showing content tailored to you, etc.
youtube-dl uses a regular expression to extract the video ID from the URL
that you give and, then, uses a "normalized", typical URL as used from the
United States, from which to proceed.
Some of the dynamic data to be gathered includes:
some time-stamp (the expire, and fexp parts of the final URL)
the cookies sent to the browser
the format in which we want to download the video (the itag part of the final URL)
throttling information (the algorithm, burst, factor)
some hashes/tokens used internally by them (e.g., the signature part of the final URL)
Some of the information listed above were once not required, but now they
are (in particular, the cookies that they send you). This means that the
information listed above is very likely to become obsolete, as the controls
become stricter.
You can see some of the work (with respect to the cookies) that I did in
this regard in the implementation of an external backend to use an external
downloader (a "download accelerator") with what youtube-dl extracts.
Discloser: I have committed some changes to the repository, and I maintain
the youtube-dl package in Debian (and, as a side effect, in Ubuntu).
You might want to take a look at how youtube-dl downloads the files. As YouTube changes, that program does seem to get updated rather quickly.
Youtube doesn't store FLV files, they compile your video into a SWF object. Those videos need to be either extracted or converted to FLV in order to get the FLV.
http://www.youtube.com/v/videoid
ex:
http://www.youtube.com/watch?v=C6nRb45I3e4
becomes
http://www.youtube.com/v/C6nRb45I3e4
From there, you need to convert the SWF into an flv, which can be done with ffmpeg.
If you really want to get an url of youtube video in flv or mp4 mode then use "YouTube Downloader - Version: 5.0" in Chrome you can right click on download button and copy path.
![You can get url of any format from this button][1]
http://i.stack.imgur.com/AFUWr.jpg (see this url due to i can't upload image at this time)
You can click on this button and copy url from "chrome://downloads/"
I think this may help you.

Resources