Video encoded with ffmpeg not playing in Chrome - google-chrome

I've been trying just about every single permutation of options on ffmpeg to try to get a transcoded video to display on Chrome - OSX 39.0.2171.71 (64-bit) - so far nothing has worked.
The settings I am currently using look like:
/usr/local/Cellar/ffmpeg/2.4.3/bin/ffmpeg -i source.m4v -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -preset slower -crf 23 -vf scale=640:360 target.mp4
but I've tried various options from various other answers with no success.
The video-js demo video works fine, so it must be possible somehow. Here's a dump of the encoded video:
*** General Parameters ***
- Name: test-1 (2).mp4
- Container: MP4 - QuickTime
- Size: 3.45 MB
- Duration: 32s 299ms
- Bitrate: 856 Kbps
*** Video Track Parameters ***
- Format: H.264/MPEG-4 AVC
- Bitrate: Max.: --- / Average: 721 Kbps / Min.: ---
- Frame rate (fps): Max.: --- / Average: 30.000 / Min.: ---
- Encoding profile: Baseline#L3.0
- Image size: 640*360
- Pixel Aspect Ratio: Undefined
- Display Aspect Ratio: 16:9
- Interlacing: Progressive
*** First Audio Track Parameters ***
- Format: AAC - MPEG-4 audio
- Bitrate: 128 Kbps
- Resolution: Undefined
- Rate: 44.1 KHz
- Channel(s): 2 (stereo)
- Position: Front: L R

Turns out that the metadata is in the wrong place. Adding -movflags +faststart to the ffmpeg parameter list makes it start working.

Related

Why did H.264, MPEG-4 HE AAC stop working on iphoneXS/Max?

Issue regarding NEW hardware
I have been investigating like crazy, and haven't found any hints to why my H.264 encoded videos have stopped working on these new devices.
Context: Direct from the ios device, the original is sent to s3, aws elastic transcoder then encodes the original into a more compressed H.264 preset. As of yesterday, a coworker was reporting all videos being "black", now since deliveries on these devices are being fulfilled, i've gotten confirmation. Cannot reproduce this issue on simulator. The encoded videos that are not playing, i've listed the exif data below.
Is there is anyone out there with a domain expertise in codecs, can you weigh in why a new device would fail to decode this H.264 video when devices since iphoneX and below have no problem?
➜ Downloads exiftool 30B3485D-24A3-4B6D-8B27-15B7C11FB864.mp4
ExifTool Version Number : 11.10
File Name : 30B3485D-24A3-4B6D-8B27-15B7C11FB864.mp4
Directory : .
File Size : 202 kB
File Modification Date/Time : 2018:09:24 20:35:47-07:00
File Access Date/Time : 2018:09:24 20:36:02-07:00
File Inode Change Date/Time : 2018:09:24 20:35:53-07:00
File Permissions : rw-r--r--
File Type : MP4
File Type Extension : mp4
MIME Type : video/mp4
Major Brand : MP4 Base Media v1 [IS0 14496-12:2003]
Minor Version : 0.2.0
Compatible Brands : isom, iso2, avc1, mp41
Movie Header Version : 0
Create Date : 0000:00:00 00:00:00
Modify Date : 0000:00:00 00:00:00
Time Scale : 1000
Duration : 4.12 s
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 3
Track Header Version : 0
Track Create Date : 0000:00:00 00:00:00
Track Modify Date : 0000:00:00 00:00:00
Track ID : 1
Track Duration : 4.12 s
Track Layer : 0
Track Volume : 100.00%
Balance : 0
Audio Format : mp4a
Audio Channels : 2
Audio Bits Per Sample : 16
Audio Sample Rate : 48000
Matrix Structure : 1 0 0 0 1 0 0 0 1
Image Width : 320
Image Height : 568
Media Header Version : 0
Media Create Date : 0000:00:00 00:00:00
Media Modify Date : 0000:00:00 00:00:00
Media Time Scale : 15360
Media Duration : 4.00 s
Media Language Code : und
Handler Description : VideoHandler
Graphics Mode : srcCopy
Op Color : 0 0 0
Compressor ID : avc1
Source Image Width : 320
Source Image Height : 568
X Resolution : 72
Y Resolution : 72
Bit Depth : 24
Pixel Aspect Ratio : 1:1
Video Frame Rate : 30
Handler Type : Metadata
Handler Vendor ID : Apple
Encoder : Lavf57.71.100
Movie Data Size : 202178
Movie Data Offset : 4545
Avg Bitrate : 393 kbps
Image Size : 320x568
Megapixels : 0.182
Rotation : 0
This bug resolved itself for me in iOS13 beta release. Apple got back to me and informed me that the H264 header said that my video was version 4.0 but the first H264 frame says that it's 3.1, and iOS12 will not allow that.
I was able to fix this in code by specifying my header version as 3.1
I had a similar problem to this with black video on iPhone XS Max, and it turns out that I was setting the keys kCVPixelBufferCGImageCompatibilityKey and kCVPixelBufferCGBitmapContextCompatibilityKey to YES in the sourcePixelBufferAttributes dictionary when creating the AVAssetWriterInputPixelBufferAdaptor. Commenting out those two keys from the dictionary seems to have fixed the problem.
I've figured out the reason. IPhone Xs+ supports all of the H.264 resolutions and frame rates. However certain frame rates require HEVC:
1080p # 240 fps
4K # 60 fps
Thus if you won't configure the captureSession.sessionPreset to some custom - lower resolution values:
if isFullHDVideoEnabled && captureSession.canSetSessionPreset(AVCaptureSession.Preset.hd1920x1080) {
captureSession.sessionPreset = AVCaptureSession.Preset.hd1920x1080
}
else {
captureSession.sessionPreset = AVCaptureSession.Preset.hd1280x720
}
iPhone will capture a video in H.265, and there would be the only option (.hevc) in movieFileOutput.availableVideoCodecTypes.
if #available(iOS 11.0, *) {
if movieFileOutput.availableVideoCodecTypes.contains(.h264) {
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.h264], for: connection)
}
else if movieFileOutput.availableVideoCodecTypes.contains(.hevc) {
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: connection)
}
}

ffmpeg txt from audio levels

Regards community,
I want to use ffmpeg to generate a file (txt, csv) from audio values.
Any idea?
I use this code to generate the audio levels:
ffplay -f lavfi "amovie=input.aac, asplit [a][out1]; [a] showvolume=f=1:b=4:w=800:h=70 [out0]"
Thank you a lot
The command below will generate a CSV format where the first column represents the audio frame time in seconds, the second column the overall RMS dB volume for that frame, the 3rd column RMS volume for the first channel and the last column the RMS volume for the 2nd channel.
ffprobe -f lavfi -i amovie=input.aac,astats=metadata=1:reset=1 -show_entries frame=pkt_pts_time:frame_tags=lavfi.astats.Overall.RMS_level,lavfi.astats.1.RMS_level,lavfi.astats.2.RMS_level -of csv=p=0
Output:
Duration: N/A, start: 0.023220, bitrate: N/A
Stream #0:0: Audio: pcm_f64le, 44100 Hz, stereo, dbl, 5644 kb/s
0.023220,-inf,-inf,-inf
0.046440,-inf,-inf,-inf
0.069660,-inf,-inf,-inf
0.092880,-27.330401,-22.685612,-24.414572
0.116100,-21.141091,-18.986082,-19.931269
0.139320,-20.955719,-18.549085,-19.587788
0.162540,-20.938002,-18.198237,-19.355561
0.185760,-19.852306,-20.032553,-19.941494
0.208980,-20.495281,-21.684953,-21.049508
The reset determines how often the stats are calculated. I've set the value to 1 i.e. calculated for each audio frame in isolation.

web recorded video not played in ipad

I record video from web using flash media server. Now using flex default player i tried to play video but, it will not play ipad.(ios device)
I checked that video codec and it is something like following:
libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 45.100 / 55. 45.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 10.100 / 4. 10.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
[flv # 0000000002b60220] Stream discovered after head already parsed
Input #0, flv, from 'C:\Users\Administrator\Desktop\123654789.flv':
Metadata:
canSeekToEnd : false
createdby : FMS 4.5
creationdate : Tue Jun 30 16:27:22 2015
Duration: 00:00:15.25, start: 0.000000, bitrate: 52 kb/s
Stream #0:0: Video: flv1, yuv420p, 320x227, 1k tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: speex, 16000 Hz, mono, s16, 20 kb/s
Stream #0:2: Data: none
I record video following ways:
netstream.publish("FILENAME","record");
Thanks.
Edit:
Another flv file i got which is played in ios. But when i check it's codec it something like following:
r --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab -
-enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
--enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-
libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 45.100 / 55. 45.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 10.100 / 4. 10.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, flv, from 'C:\Users\Administrator\Desktop\16402.flv':
Metadata:
major_brand : 3gp4
minor_version : 0
compatible_brands: isom3gp4
encoder : Lavf55.45.100
Duration: 00:00:13.23, start: 0.000000, bitrate: 304 kb/s
Stream #0:0: Video: flv1, yuv420p, 320x240, 300 kb/s, 15 fps, 15 tbr, 1k tbn
, 1k tbc
Stream #0:1: Audio: mp3, 22050 Hz, mono, s16p, 0 kb/s
How, can i record/convert flv like below?
It's a normal behavior that iPAD didn't play your FLV video because simply it's not supported by iOS, as mentioned here by Apple :
iOS supports many industry-standard video formats and compression standards, including the following:
H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30 frames per second, Low-Complexity version of the H.264 Baseline Profile with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats
H.264 video, up to 768 Kbps, 320 by 240 pixels, 30 frames per second, Baseline Profile up to Level 1.3 with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats
MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats
Hope that can help.
You should transcode it into H.264 mp4 stream on Flash Media Server and feed that stream into your flex application. If you record the video by Adobe Live Video Encoder there is an option to set the output format either. I did that a few years ago.

Manually calculate h264 video bitrate

I have a problem.
I'm currently trying to manually calculate the bitrate of a .mkv video I want to encode to get a specific file size so I can use that in my batch file.
Size I want the clip to be: 1900 MB --
Duration: 2587 seconds --
Audio bitrate: 1509 kbps
My current calculation is:
1900MB*1024 seconds 1509/8 seconds
(1945600 - (2587 x 188,625) ) / 2587 = 563,44303247004252029377657518361 KBps
563,44303247004252029377657518361 * 8 = 4507,5442597603401623502126014689 kbps
I tried encoding with this bitrate, however the file size won't match 1900 MB, so I
used a bitrate calculator and after putting in my settings it says for 1900 MB, the video needs a bitrate of 4647 kbps (encoded with this bitrate, and it was 1899 MB).
My question is, what did I miss in my calculation?
"kilo" is 1024 for data size, but 1000 for bitrate.
1992294400 bytes for whole file [1900 MB * 1024 * 1024]
-487972875 bytes for audio [1509/8 * 1000 * 2587]
= 1504321525 bytes for video [4652/8 * 1000 * 2587]
video bitrate: 4652 kbps
This result more closely matches the calculator you used than your result, although I can't explain the remaining discrepancy of about 5kbps. Perhaps the calculator accounts for framing overhead or seek tables or some other metadata.
I would trust the calculator, since using its value gave you results very close to your goal.

html5 video tag codecs attribute

I am trying to specify a specific video/audio codec in the video tag using
<video poster="movie.jpg" controls>
<source src="movie.mp4" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'/>
<p>This is fallback content</p>
</video>
but can't find the right codecs statement to play the video , i have downloaded a video analyser and can see that its an avc1 and can see that the audio map.40.2 but can work out the rest of the codec, what does the 4d401e mean in the above ?
Cheers
Toby
The codecs parameter is specified by RFC 6381. Specifically, see section 3.3 for the meaning of avc1 and mp4a values.
In the case of avc1.4D401E, avc1 indicates H.264 video, and this is followed by a dot and three 2-digit hexadecimal numbers defined by the H.264 standard:
profile_idc
the byte containing the constraint_set flags (currently constraint_set0_flag through constraint_set5_flag, and the reserved_zero_2bits)
level_idc
Some examples:
avc1.42E01E: H.264 Constrained Baseline Profile Level 3
avc1.4D401E: H.264 Main Profile Level 3
avc1.64001E: H.264 High Profile Level 3
These are also the second, third, and fourth bytes of the Sequence Parameter Set and the AVC Configuration Box in an MP4 file. You can dump these bytes using a program such as mp4file: mp4file --dump movie.mp4. Look for the avcC (AVC Configuration) Box and the hexadecimal values for AVCProfileIndication, profile_compatibility, and AVCLevelIndication.
As for mp4a.40.2, mp4a indicates MPEG-4 audio. It is followed by a dot and a hexadecimal ObjectTypeIndication (objectTypeId in mp4file output), which can be looked up on the MPEG4 registration site. If this hexadecimal value is 40 (ISO/IEC 14496-3 Audio), it is followed by another dot and an audio object type in decimal. These are listed in the ISO/IEC 14496-3 standard and on Wikipedia, and correspond to the first 5 bits of the DecoderSpecificInfo (decSpecificInfo) (unless these bits equal 31, in which case add 32 to the next 6 bits). mp4a.40.2 indicates AAC LC audio, which is what is usually used with H.264 HTML5 video.
For example, codecs="avc1.42E01E, mp4a.40.2" would be correct for the movie below:
$ mp4file --dump movie.mp4
...
type avcC (moov.trak.mdia.minf.stbl.stsd.avc1.avcC) ◀━━ avc1
configurationVersion = 1 (0x01)
AVCProfileIndication = 66 (0x42) ◀━━ 42
profile_compatibility = 224 (0xe0) ◀━━ E0
AVCLevelIndication = 30 (0x1e) ◀━━ 1E
...
type esds (moov.trak.mdia.minf.stbl.stsd.mp4a.esds) ◀━━ mp4a
version = 0 (0x00)
flags = 0 (0x000000)
ESID = 2 (0x0002)
streamDependenceFlag = 0 (0x0) <1 bits>
URLFlag = 0 (0x0) <1 bits>
OCRstreamFlag = 0 (0x0) <1 bits>
streamPriority = 0 (0x00) <5 bits>
decConfigDescr
objectTypeId = 64 (0x40) ◀━━ 40
streamType = 5 (0x05) <6 bits>
upStream = 0 (0x0) <1 bits>
reserved = 1 (0x1) <1 bits>
bufferSizeDB = 0 (0x000000) <24 bits>
maxBitrate = 78267 (0x000131bb)
avgBitrate = 78267 (0x000131bb)
decSpecificInfo
info = <2 bytes> 11 90 |..| ◀━━ 2 (first 5 bits in decimal)
...
You can use MP4Box tool to find out codec strings in RFC6381 format. Still you have to join them with commas.
You can use this command:
MP4Box -info big.mp4 2>&1 | grep RFC6381 | awk '{print $4}' | paste -sd , -
mark4o gives by far the best explanation I've seen of how to decipher codec information. Excellent.
One piece which may require a little more detail is how to break out the specific audio object type from the decSpecificInfo value. Finding the "mp4a.40" part is very clear, the ".2" section can be a little tricky.
We start with a sequence of single byte hexadecimal values: "11 90" in mark4o’s example or "12 08" in my case. Both of those are a total of 2 bytes... there may be more values but only the first 2 matter for finding the object type (and usually only the first byte). We're looking for individual bits so convert each digit in the hexadecimal values to binary; there should be 4 binary digits for each hexadecimal digit. Take the first 5 binary digits — 4 from the first hex digit, 1 from the next — and convert that binary value to decimal. Here are the steps:
Example 1 (11 90):
Starting value: 11 90
Separate the hex digits: 1 1 9 0
Convert each digit to binary: 0001 0001 1001 0000
Take the first 5 bits: 0001 0
Combine into binary value: 00010
Convert to decimal: 2
Example 2 (12 08):
Starting value: 12 08
Separate the hex digits: 1 2 0 8
Convert each digit to binary: 0001 0010 0000 1000
Take the first 5 bits: 0001 0
Combine into binary value: 00010
Convert to decimal: 2
They are the same object type in spite of having different decSpecificInfo values.
You could also simply do this to find the right codec infor:
go to the folder containing your video file, lets assume the file is called movie.mp4,
The run the command:
vlc movie.mp4
assuming you have vlc installed, if the video plays vlc will have the correct codec information,
Click on the tools menu above, a drop down list will be displayed with an option to view the codec information as below.