Video file formats for H.264 - mp4

I need to develop a small module, that can read and write h.264 packets to a container file. So far I have understood, typically h.264 encoded packets are stored in a mp4 file.
My question is, can h.264 encoded packets be stored in other file containers like in ogg file or in mkv file or in webm file.
If yes, how do I convert a mp4 file to an ogg file or mkv file or webm file, keeping same h.264 encoded packets in file.

H.264 can go into MP4, MKV, webm (pretty much same as MKV), FLV, F4V and others.
Please check https://en.wikipedia.org/wiki/Comparison_of_video_container_formats
For conversion I'd use ffmpeg which will do most combinations.
ffmpeg -i inputfile.xyz -vcodec copy ... (specify output file and audio stream)

Related

Encoding video for streaming with multiple subtitle streams in VLC

I am implementing an offline video streaming service, so our users can have the encrypted videos on their computers and open them only by using our streaming app.
So what I need is to stream a freshly decrypted video file directly to a local VLC client so I don't have to save it on disk. A minimum working example would be:
cat my_video.mp4 | vlc -
But this only shows the video and audio tracks, no subtitles.
I want to know if there is a way to encode a video so that this would work with 3 audio tracks and 3 subtitle tracks.
I would also settle for an answer explaining that it is not possible and why not.
More details below:
I have 3 audio tracks and 3 subtitle tracks and I am using FFMPEG.
(The original format of the videos is mp4 with an h264 encoding)
Currently, I am able to make streamable .mp4 files, thanks to this answer, and also to make .ts files that will show the video and the 3 audio options but not the subtitles. The command I am using is this:
video_name=demo_0101.mp4
sub_name=demo_0101.srt
output=0101.mp4 # Or `.ts`
ffmpeg\
-i en_raw/$video_name -i pt_raw/$video_name -i es_raw/$video_name\
-i en_subs/$sub_name\
-i pt_subs/$sub_name\
-i es_subs/$sub_name\
-map 2:v\
-map 0:a:0 -map 1:a:0 -map 2:a:0\
-map 3:s -map 4:s -map 5:s\
-c:v libx264 -crf 22\
-movflags faststart\ # (This line is only necessary for .mp4)
-c:a:0 aac -c:a:1 aac -c:a:2 aac\
-c:s:0 mov_text -c:s:1 mov_text -c:s:2 mov_text\
$output
The problem is: The subtitles are not recognized (don't show up at all) using the .ts format and when using .mp4 VLC reports an error:
Unidentified codec:
VLC could not identify the audio or video codec
Please note when not streaming the .mp4 version works with all audios and the subtitles, i.e.:
vlc my_video.mp4
In case someone is wondering I plan on selecting the which subtitle and audio to play from command line with the VLC options: --audio-track 1 --sub-track 0
I hope someone can help me. Thanks in advance.
I was unable to find a way to encode the subtitles directly on the video which would be the preferable solution. However, I found a VLC command that will display the subtitle file together with the streaming video:
cat 0101.mp4 | vlc --sub-file en_subs/demo_0101.srt
This is not ideal for 2 reasons:
It does not work with the .ts format only .mp4.
This requires me to save the original subtitle files on the user disk.
I will not mark this solution as the accepted answer because if it is possible to stream the video directly with the subtitles I want to know, and I also believe that such answer would be helpful for others that happen to read this page.

How to add MOV file header to raw data written file with ffmpeg?

I am going to record H264 encoded video stream data in iOS using swift.
I am not familiar with video codec formats so don't know how to do this. But I've tried to write the H264 raw video data to the file sequently and see its file Info. I am surprised that it has almost video file info (compared with standard mp4, MOV file). The only missing info is video duration, file size, overall bit rate, encoded data, etc. So I am just wondering if video can play if I add the MOV file header to this file manually. Spent few hours to googling how to add MOV file header with ffmpeg but stacked. Any help would be appreciated. Thanks
You can nominally use ffmpeg to do this:
ffmpeg -i in.h264 -c copy out.mov
However, due to a bug in ffmpeg relating to generation of PTS for video streams with multiple B-frames, the output video may not play smoothly. Test and check.
If it doesn't there's a workaround which involves using mp4box from GPAC.
mp4box -add in.h264 -new out.mp4
and then
ffmpeg -i out.mp4 -c copy out.mov

How to overlap multi mp3 files to one mp3 file with ffmpeg?

Hi all
I have multi mp3 files, each file have difference sound. Now i need overlap all of them to one file to have a mp3 file with all other sound. Can i do that with ffmpeg or other tool?
Thank for your help.
IMO, can't be done with ffmpeg.
I would decode all mp3 to .wav files and use Audacity to mix all sources to a single stereo .wav. Then, you can easily reencode this to mp3.
Audacity

How can I Access/extract raw(headless) audio data from a caf file on iPhone?

I am working on a project that requires me to send raw headerless ulaw or linear pcm data to a server.
I am using the AVAudioRecorder and I can save out audio files to the phone quite easily, but the problem is that it no matter what I try and do, they get wrapped in a caf file or stamped with some kind of header.
It's my understanding that a caf file is just a wrapper file for raw audio data and that this audio data can be in various formats including linear pcm and ulaw.
So my questions are, how can I generate a raw audio file without the caf wrapper to begin with (ie just the headerless raw audio stuffed into a file) or if I record a caf that contains the raw Ulaw or linear pcm audio data, how can I easily go in and extract just the raw audio data from the caf file and leave everything else behind.
If the audio data in the CAF is already in the format you need it in, I'd use the AudioFile API to grab the caf file's audio data and write them to a headerless/RAW file before uploading to my server.
If you need to convert the CAF's data, use the ExtAudioFile API instead. Either way, pretty straightforward.
http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html
http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/ExtendedAudioFileServicesReference/Reference/reference.html
If you use the Audio Queue API for recording, instead of AVAudioRecorder, you will have access to raw PCM sample buffers, and can write those out to a flat file for later sending to your server.

jwplayer can read only flv files?

I have a doubt jwplayer can read only flv files or it can read every files
With over one million active users,
the JW Playerâ„¢ is the Internet's most
popular and flexible open source media
player. It can support playback of any
format the Adobe Flash Player can
handle (FLV, MP4, MP3, AAC, JPG, PNG
and GIF).
http://www.longtailvideo.com/
EDIT
If you need to deal with any other formats, you can run the conversions server side using ffmpeg
Reference
http://www.ffmpeg.org/