How to programmatically output fragmented mp4 file using libavformat? - mp4

I want to use mp4 file format for live streaming, which is not possible with an unfragmented mp4 file, as the moov atom is generally written at the end of the file. I need to generate a fragmented mp4 file to transfer it over a network for live streaming. I am using libavformat. The problem is, I can write unfragmented mp4 files easily with libavformat, but I don't know how to write a fragmented mp4 file. So, how to write a fragmented mp4 file using libavformat?

I don't think you are looking for fragmented mp4 (FYI a fragmented mp4 is usually called .ismv) ISMV requires a media server and specialized client to stream.
I think what you are looking for is faststart. This simply moves the moov atom to the start of the file. ffmpeg comes with a qt-faststart utility that will do this for you. Check you distrobution.

You can use Bento4 library to do this easily. Download from here http://www.bento4.com/downloads/ and use the binary mp4fragment.
mp4fragment sourcefile destinatiofile

Related

Download Result of Source Destination (Web Audio API)

I'm building a tool to edit audio with the Web Audio API.
Here is where I'm stuck:
...
source
.connect(gainNode)
.connect(analyser)
.connect(analyser2)
.connect(audioCtx.destination);
};
What I've written (which ends with the code above) successfully allows the user to upload a file, apply effects, and listen to it on play(). How would I then allow the user to click a button to export the results to a WAV file?
I've tried several methods online that have not worked for my use case.
Please let me know if more code is needed. Thank you for taking a look!
If you want a WAV file, I think you have to do that yourself. WAV files are quite simple. In this case, you'll need to add either a ScriptProcessorNode or AudioWorkletNode just before the destination to capture all the audio and convert it to a WAV file that can be downloaded.
If a compressed file is ok, you can look into MediaRecorder to save the data for you.
I ended up solving this by writing an entirely different script to download the file using OfflineAudioContext.
My original script plays the audio with effects, and the second script downloads it with the same effects. Now to figure out why there is latency on the effects while using OfflineAudioContext.

Video compression for backup purposes

I'd like to know if there is a method/application to further compress MP4 files without loss as compressed files (zip-like) for archival purposes, even if I had to make a bigger file before recompressing.
I don't need to play the videos immediately, it's to have a medium to long term backup, so the zipping/unzipping process wouldn't be an issue for me.
Thanks.
No. The last step in video compression is a lossless entropy encoder similar to zip. What you are asking to do has already been done to the file.

Read HEVC frames using matlab

I want to read HEVC compressed video and extract the frames in compressed(encoded) video file to extract some information from frames like motion vectors etc..
can anyone help me how to read the compressed HEVC video file, and how to extract frames using matlab in windows OS.
VideoReader in matlab will read upto H.264 encoded videos but not H.265/HEVC encoded videos.
I have downloaded few HEVC compressed videos from http://www.elecard.com/en/download/videos.html and downloaded the codec tool kit from this website , I can play these videos.
There is no official release for HEVC/H.265 codec in MATLAB because HEVC is not a royalty-free software and it is the reason that the tech Giants make an alternative video coding without any licensing fee. Therefore, HEVC is currently used mostly in scientific literature nowadays.
However, you can encode/decode YUV format video data in HEVC using HM reference software which is available in this link. To encode, you need Visual Studio installed on your Windows machine. Firstly, open your command prompt and type:
msbuild /p:Configuration=Release HM_vc2015.sln
After building the project, you can find some files in /bin folder. Then, you should change your current directory to /bin folder using cd command and type:
TAppEncoderStatic.exe -c your_config_file.cfg -i your_video_data.yuv
Hence, str.bin file will be created in /bin folder which can be renamed using your_config_file.cfg or command-line options which is thoroughly explained in the software manual. Also, you can find good config files in the /cfg folder. To decode the str.bin just type:
TAppDecoderStatic.exe -b str.bin -o dec.yuv
Note that dec.yuv is the decoded output video data in the decoder. Also, you can see the decoded and original video sequence using a YUV viewer. Moreover, you can find a good dataset here.
AFAIK there is no public code or library that enables reading an HEVC datastream directly from MATLAB.
When faced with this same problem, I modified the reference HEVC decoder to write a separate CSV file as it decodes the HEVC video. MATLAB can then read the CSV file.
I borrowed this approach from GitlHEVCAnalyzer. See TSysuAnalyzerOutput.cpp, where the author writes a number of different text files during HEVC decoding. The analyzer then reads the text files.

Prepending a header to a headerless .m4a file

I have some .m4a files that were captured from a radio broadcast stream. They are playable using mpd (an open source Music Playing Daemon for *nix), but iTunes won't open them (nor will several other music players that should be able to play .m4a files). When I looked at the file in hex format, and compared it to an .m4a file from iTunes, it appeared that the file from the broadcast stream did not have any header info.
So I figured I'd try prepending some header info to the file, to see if that would make it playable by these other players.
I've tried to read the technical doc about the .m4a file format to understand how the header is structured, but it's far too complex for me to follow (most of the doc is about the coding, which isn't pertinent to this). The header seems fairly simple, conceptually - I can see 4-character tags, variable length data, and there are presumably some length codes to allow these to be split apart. It doesn't seem to contain any significant data about the actual audio data (like its total length), making me hopeful that I might be able to get by by simply copying the header from an .m4a file and prepending it to these headerless files.
I'm unable, though, to manually parse (that is, reverse-engineer) the header in order to even experiment with this. Can someone describe how to identify a complete header at the front of a .m4a file?

How to make Red 5 media server stream different formats of files?

I need to stream both audio and video files from the Red 5 server. By default Red 5 only supports flash, but I need to add support for other file types too.
I need to dynamically (on the run time) transcode the media file in one format to desired formats as per client request. Is it possible ? How to go for it ? I have been reading of vlcj project, but dont know how to integrate them.
If audio / video transcoding is not possible in Red 5, is there any other open source alternative I can look forward to ?
Any help will be really appreciated...
Thanks !
Check out the StreamableFileFactory bean inside your red5-common.xml, to see what kind of files can be streamed by default (flv, mp3, mp4, m4a). If you copy any of these files in your red5 service's streaming directory, it will be able to play it.
If the source you need to stream is in different format (like youtube uploads), then the best way for you to go is ffmpeg.
You build it to your server, then
from inside your red5
service check whether there are any
unsupported files in your streaming
directory (should be a scheduled job), and
if so, use ffmpeg with the proper
parameters to convert the new files
to streamable formats.
that's it.