Encode iOS compatible h264 audio stream with FFMPEG - ios

I am using FFMPEG with Python to encode a low bit rate version of videos that I import. I would like the output to be playable on several devices, including Roku and iOS. This link states that Apple supports H264 High profile, level 4.1 and MP3 audio.
ffmpeg -preset veryslow -y -profile:v high -level 4.0 -movflags +faststart -codec:a libmp3lame -qscale:a 2 -s 1280x720 out.mp4
The resulting videos play fine in an HTML5 browser on a computer. However, on the iPhone the video appears but the audio stream does not play. Is there an issue with the mp3 settings?
From ffprobe:
[STREAM]
index=1
codec_name=mp3
codec_long_name=MP3 (MPEG audio layer 3)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=s16p
sample_rate=44100
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=-1105
start_time=-0.025057
duration_ts=2321489
duration=52.641474
bit_rate=94949
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=2016
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]
I tried using AAC, but did not get good results with the native FFMPEG encoder

The document you reference is for HTTP Live Streaming, which uses a transport stream format, not an ISO mp4 format. Either way I have found many issues with mp3+video in ios. My recommendation is to use AAC (-acodec fdk-aac) instead of mp3. It is just as universally supported, and will provide you with better audio at lower bitrates. If that is not an option, try to specify all audio settings on the command line (-channles -samplerate, etc)

Related

how to embed subtitle to a video file without burn (html5)

i've a cdn hosting and there are some video files on it. and i've subtitles for videos. as you know, osx or ios doesn't allow subtitles on fullscreen mode. i've found a solution with ffmpeg (burning) but it burns video with hardcode:
https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo
is there any other way to do it without hardcode (maybe a media server)? because i've 5 different subtitles for each video file. and can't do it with hardcode.
any helps would be great..
best regards.
Well, what I'm suggesting is like this.
ffmpeg -i input_video -i input_sub -c:s mov_text -c:v copy -c:a copy output_video
Here mov_text is the codec for subtitles and this will soft embed the subtitle without burning it in to the video. All other streams will be copied as it is. See here for a demo.
Hope this helps!

How to convert .mp4 file to .webm using avconv tool

I have .mp4 file and I want to convert it to .webm with the same quality by avconv tool,
and vice from .webm to . mp4 with the same quality
document fuzzy to me.
That's not possible. WebM cannot contain MPEG media (video or audio.) So you can't repack ("remux") the media from mp4 to webm. You would need to re-encode them ("transcode" them), with VP8 or VP9 as the video format and Vorbis as the audio format. Thus you can't have the same quality, since transcoding from one lossy format to another always loses some quality.
So your only option is to transcode.

live555 Server streaming x264 not working, how to debug?

Before diving into the SDK Version, i simply tried to stream an x264 encdoed video to VLC. Streaming MP3 Works, but x264 takes a while then i get an error, that vlc cannot open the file.
1) Downloaded Live555 Server
2) Started EXE which states the url to use as: rtsp://172.18.1.85/<filename>
3) In VLC i am using: rtsp://172.18.1.85/fantastic.264 As the server output says "Each files type is inferred from it's name suffix" so i renamed the file from fantastic.mp4 to fantastic.264
As i've stated an mp3 stream works fine in the same directory where fantastic.264 is placed.
The file ending was correct but it wasn't an "elementary h264 stream". So I had to reconvert it to an elementary h264 file.
Quick Fix:
ffmpeg -i fantastic.mp4 -vcodec libx264 -f h264 fantastic.264
You can get here more Information:
What does Elementary Stream mean in Terms of H264

Streaming Technique from pocketcast in xcode

I've been asked by my client whether it is possible to download a video and stream it once a bit has downloaded, just like pocketcasts does. His reasoning is this will allow him to store his video files on a site such as godaddy and bypass the need to stream the file to the phone which normally requires a dedicated server.
Is this even possible? if so do you know anywhere I can look to find out how pocketcasts does it? At the moment my app just streams an mp4.
Thanks for looking,
Matt
Since you're targetting iOS, HLS (HTTP Live Streaming) is your friend: https://developer.apple.com/streaming/
Please see my answer here for how you can use it: Simultaneously downloading and playing a song that is pieced together from multiple URLs
It's very easy to run a long movie through the mediafilesegmenter tool from Apple (or FFMPEG) which spits out a number of small .ts files (MPEG 2 Transport Stream). Then you create a manifest (a .m3u8 file) which describes how these files fit together (which mediafilesegment will create for you too!). Then you just put the manifest file and the .ts files on a hosting provider (like GoDaddy) and you're all set.
For example, given a file called test.mp4, first turn it into a .ts file with ffmpeg:
ffmpeg -i test.mp4 -acodec copy -vcodec copy -bsf h264_mp4toannexb test.ts
Then turn it into a series of HLS segments with mediafilesegmenter (the same can be done using the ffmpeg segment muxer, but mediafilesegmenter seems to be more robust):
mediafilesegmenter -t 3 test.ts
The result is a bunch of 3 second clips (that's what -t 3 means) and an manifest file called prog_index.m3u8. The contents of that look like:
#EXTM3U
#EXT-X-TARGETDURATION:3
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:2.99520,
fileSequence0.ts
#EXTINF:2.99520,
fileSequence1.ts
#EXTINF:2.99520,
fileSequence2.ts
#EXTINF:2.99520,
fileSequence3.ts
...
#EXTINF:0.37440,
fileSequence75.ts
#EXT-X-ENDLIST
Simply putting all of the .ts files and the .m3u8 file on a web server and pointing your AVPlayer or MPMoviePlayerController in iOS at the URL for the .m3u8 will get you an excellent streaming performance.

AVAudioPlayer M4A file converted from AIFF produces different latency than M4A converted from ADTS AAC

While working on a rhythm music game, I noticed that AVAudioPlayer has a latency between the reported .currentTime and the actual location within an audio file, that varies according to the file format.
For instance, playing an .m4a file will produce lower latency than playing an .aac file (ADTS AAC).
That's somewhat understandable and I came to accept this already (as the latency was a constant according to file type).
What I don't understand, is why these different latencies might also happen for 2 kinds of .m4a files, those converted from an original AIFF file, and those first converted to ADTS AAC and then converted to .m4a
In other words:
If I run:
afconvert -f m4af -d aac my_aif_file.aif
I get a file playing in lower latency than a file that was created like this:
afconvert -f adts -d aac my_aif_file.aif
afconvert -f m4af -d aac my_aif_file.aac
Any explanation/solution to understand these different outcomes will be appreciated.
Found the issue - it's the conversion itself.
When converting to adts aac the converted audio has a prefix of about 40ms of silence...
Weird...

Resources