FFMPEG convert from MP3 to M4A- Getting errors - audio

I'm working on Windows 10 x64, build ffmpeg-20180916-5109c38-win64-static.
I have a folder of MP3 audio files that I want to convert to M4A.
This is the command that I'm running:
FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata 0 -c:a aac -b:a 192000 "%~nG.m4a"
This scans my bin filder and converts all files. This works great for converting video files from MOV to MP4 (using a different code string) but I keep getting errors such as:
[ipod # 0000025507991b40] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[libx264 # 0000025507e45180] using SAR=1/1
[libx264 # 0000025507e45180] MB rate (129960000) > level limit (16711680)
[libx264 # 0000025507e45180] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 # 0000025507e45180] profile High 4:4:4 Predictive, level 6.2, 4:4:4, 8-bit
[libx264 # 0000025507e45180] 264 - core 157 r2932 303c484 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[ipod # 0000025507991b40] Could not find tag for codec h264 in stream #0, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --
[aac # 0000025507e60100] Qavg: nan
Conversion failed!
What's the best way to convert to M4A? I'm doing this to reduce disk space.

Add -c:v copy. FFmpeg is trying to transcode the cover image. Although you shouldn't be getting that error even when transcoding - I'd consider that a bug.

Skipping inclusion of video stream also works.
-vn
Add this before output file.

Related

How do you use FFMPEG to transcode h264_qsv from Apple PRORES Quicktime?

I am trying to transcode an Apple Prores 444 to H.264 using qsv without success.
If I use this command line:
ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac -pix_fmt qsv chris.mp4
I get:
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_qsv # 0x56265b81a800] Selected ratecontrol mode is unsupported
[h264_qsv # 0x56265b81a800] Low power mode is unsupported
[h264_qsv # 0x56265b81a800] Current frame rate is unsupported
[h264_qsv # 0x56265b81a800] Current picture structure is unsupported
[h264_qsv # 0x56265b81a800] Current resolution is unsupported
[h264_qsv # 0x56265b81a800] Current pixel format is unsupported
[h264_qsv # 0x56265b81a800] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
user#NUC:~$ ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac -pix_fmt qsv chris.mp4
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:1
Conversion failed!
If I use:
ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac chris.mp4
I get:
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:1
Conversion failed!
user#NUC:~$ ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac chris.mp4
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_qsv # 0x55b3bb6e8800] Selected ratecontrol mode is unsupported
[h264_qsv # 0x55b3bb6e8800] Low power mode is unsupported
[h264_qsv # 0x55b3bb6e8800] Current frame rate is unsupported
[h264_qsv # 0x55b3bb6e8800] Current picture structure is unsupported
[h264_qsv # 0x55b3bb6e8800] Current resolution is unsupported
[h264_qsv # 0x55b3bb6e8800] Current pixel format is unsupported
[h264_qsv # 0x55b3bb6e8800] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
I cannot get ANYTHING to work. I can transcode other h264 files without issue. I cannot seem to transcode this prores file.
Here is a link to the source file if anyone can help I would REALLY appreciate it...
https://www.dropbox.com/s/ejrfzad20yzaifm/10minute_Pipeline_Test.mov?dl=1
I use H264_QSV daily, and I find you have to declare the QSV device as being available.
Try this:
ffmpeg -err_detect ignore_err -hide_banner -loglevel verbose -init_hw_device qsv:qsv,child_device_type=qsv ^ -hwaccel qsv -hwaccel_output_format qsv -i "input.mov" -q:v 30 -preset slow -c:a aac output.mp4
There are many more options that can be added to improve efficiency, change the quality (the -q:v setting), etc.
I've found that QSV speeds things up so much that you can use a -preset of slow or very slow to get more compression for a given quality setting without significantly increasing the time it takes to convert the file.
I may not have done the copy as well as I should have.
This is a more complete copy of how I use ffmpeg.
ffmpeg -err_detect ignore_err -hide_banner -loglevel verbose -stats -benchmark -init_hw_device qsv:qsv,child_device_type=qsv ^
-hwaccel qsv -hwaccel_output_format qsv ^
-i "input file" ^
-c:a aac -q:a 1.9 -strict normal -sws_flags lanczos ^
-vf "vpp_qsv=cw=704:ch=480:cx=11:cy=0:w=640:h=480" ^
-async_depth 128 -q:v 28 -c:v h264_qsv -preset veryslow (a bunch of optimization options on how I want the compression to be done go in here, which can be discussed separately) -movflags +faststart "output file.mp4"
This is on Windows so the carat "^" is the command line continuation character.
-err_detect suppresses some of the more useless messages. -hide_banner suppresses things that I normally don't need to see at all.
-loglevel is usually set to "info" or "quiet", but if you want to know exactly which codecs are being used, set it to "verbose" as it is here.
This is the simple answer to the original question, "Am I using the QSV codec?".
-strict normal is optional, but I found some applications didn't do well with some of the newer optimizations. It does not appear to increase file size to any significant extent, and I don't run into problems running videos on old equipment.
I put the audio processing first as it seems to work better that way.
I let the codec choose the bit rate by setting the quality, as with the video (see below).
I have also included an example of the vpp_qsv video processing filter, as I find it speeds up many operations. It can, of course, be left out if you don't need it. I put it before the compression codec: ffmpeg will process them in the proper order, but I find it's easier to keep track of what's going on if I put the commands in about the same order as they will eventually be processed. When I put the commands in this order and "verbose" is on, ffmpeg reports that the output of the vpp_qsv filter remains in video memory as the input to the h264_qsv codec. This speeds things up in my tests: or, at least, it reduces the CPU load so other programs can run at the same time.
-async_depth is optional, increases the number of frames that are read before compression is done; I find this also usually makes things go a bit faster. -q:v is the compression quality setting: I've found 28 to 30 gives me good results for watching videos on a reasonably large TV, but you will have to make tests for yourself to see what setting is right for you. Doing this is much, much better than guessing what bitrate you need, the codec can do better optimizations, and so on. You will, in most cases, get variable bit rate compression, and sometimes variable frame rates. This improves compression for parts of the video that don't have much going on, while still providing higher bit rates when needed. You may be surprised at how low a bit rate can be produced this way and still have a good quality video.
I put -movflags +faststart in ALL of my MP4 videos. This moves a copy of the MOOV atom from the end of the video to the beginning. This does at least two things. First, for many players, the video will start playing faster as the information the player needs about the video is read immediately. Second, if an MP4 file ever gets truncated and the MOOV atom is missing, you will not be able to play the file at all. There are programs that pretend to be able to recover the missing information, but I have yet to see one actually work. But if the MOOV atom is also included at the beginning of the video, you will at least be able to start processing the video, and should at least get to the point where the file is damaged. It's cheap insurance, and only takes a moment or two. (This won't work if your output is a live stream, the video has to be "finished" before the atom is created.)
-stats and -benchmark are optional, I like to see how fast processing is going and be able to compare it to other times I process videos to see if any changes I make to the options are helping or not.
If there is an interest in the various vpp_qsv filter options, or in what other compression settings I use, or what settings will allow videos to work with Roku Media Player, let me know which topic I should post that in.

Unsupported presentation (0x20400003)

so I'm trying to get a really simple livestreaming system running through Azure Media Services. I've got ffmpeg installed on a Raspberry Pi w/ a USB camera, and I'm just trying to get the camera feed received through Azure so I can start tinkering with the Media Player. The ffmpeg command appears to run without a hitch, but whenever I attempt to preview the stream, I get a the following error:
"The video playback was aborted due to a corruption problem or because the video used features your browser did not support. 0x20400003"
The 0x0400003 part of the code is listed in the docs (http://amp.azure.net/libs/amp/latest/docs/index.html#error-codes)
as meaning the presentation of the video is not supported, but I can't find what that actually means in terms of what's wrong.
I'm using the following ffmpeg command for encoding,
ffmpeg -v verbose -framerate 30 -r 30 -i /dev/video0 -vcodec libx264 -preset ultrafast -acodec libfdk-aac -ab 48k -b:v 500k -maxrate 500k -bufsize 500k -r 30 -g 60 -keyint_min 60 -sc_threshold 0 -f flv rtmp://{Azure channel address}/channel5
which results in the following output:
ffmpeg version N-83743-gd757ddb Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --enable-gpl --enable-libx264 --enable-nonfree --enable-libfdk-aac
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
[video4linux2,v4l2 # 0x1f7a430] fd:3 capabilities:84200001
[video4linux2,v4l2 # 0x1f7a430] Querying the device for the current frame size
[video4linux2,v4l2 # 0x1f7a430] Setting frame size to 640x480
[video4linux2,v4l2 # 0x1f7a430] The driver changed the time per frame from 1/30 to 1/15
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 169752.581724, bitrate: 73728 kb/s
Stream #0:0: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 640x480, 73728 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 # 0x1f89eb0] w:640 h:480 pixfmt:yuyv422 tb:1/30 fr:30/1 sar:0/1 sws_param:flags=2
[auto_scaler_0 # 0x1f8a9c0] w:iw h:ih flags:'bicubic' interl:0
[format # 0x1f8a040] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[graph 0 input from stream 0:0 # 0x1f89eb0] TB:0.033333 FRAME_RATE:30.000000 SAMPLE_RATE:nan
[auto_scaler_0 # 0x1f8a9c0] w:640 h:480 fmt:yuyv422 sar:0/1 -> w:640 h:480 fmt:yuv422p sar:0/1 flags:0x4
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 # 0x1f7d650] using cpu capabilities: ARMv6 NEON
[libx264 # 0x1f7d650] profile High 4:2:2, level 3.0, 4:2:2 8-bit
[libx264 # 0x1f7d650] 264 - core 148 r2762 90a61ec - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=31 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=cbr mbtree=0 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=500 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
Output #0, flv, to 'rtmp://{Azure Channel Address}/channel5':
Metadata:
encoder : Lavf57.66.103
Stream #0:0: Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv422p, 640x480, q=-1--1, 500 kb/s, 30 fps, 1k tbn, 30 tbc
Metadata:
encoder : Lavc57.82.100 libx264
Side data:
cpb: bitrate max/min/avg: 500000/0/500000 buffer size: 500000 vbv_delay: -1
[flv # 0x1f7c1c0] Failed to update header with correct duration.ate= 501.5kbits/s speed=0.25x
[flv # 0x1f7c1c0] Failed to update header with correct filesize.
frame= 2155 fps=7.5 q=-1.0 Lsize= 4392kB time=00:01:11.80 bitrate= 501.1kbits/s speed=0.25x
video:4350kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.974120%
I'm not sure if the header errors are significant, as the program continues to run as expected, but please let me know if there's anything here that's blatantly an issue, or whether there's a meaningful explanation for what the presentation issues are.
Ok here is a quick helper for Raspberry PI Live streaming to Azure Media Services that worked out well for me.
There are a few tricks you can do here to make it work a lot better. The problem is mostly with the FFMPEG command, but you can optimize encoding as well by using the hardware acceleration support on the PI (if you have 2 or higher).
I initially followed this guide to build FFMPEG.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
I had to compile the x264 codec first.
When compiling FFMPEG i had to use the "make -j4" to compile on all 4 cores of the latest Raspberry PI B+ or 3.0. Made it compile much faster.
Compilation took a long time on the PI anyways, so I let it run overnight.
Once I had a compiled FFMPEG, I used the new H264 Open Max (OMX) acceleration feature.
add "-enable-omx -enable-omx-rpi" to ./configure options
use FFMPEG Encoder option "-c:v h264_omx"
see for details - https://ubuntu-mate.community/t/hardware-h264-video-encoding-with-libav-openmax-il/4997/11
Once i had that working I did a quick test to make sure I could successfully capture an MP4 File
ffmpeg -framerate 30 -r 30 -s 640x360 -i /dev/video0 -vcodec h264_omx -preset ultrafast -acodec libfaac -ab 48k -b:v 2000k -bufsize 500k -g 60 -keyint_min 60 -sc_threshold 0 out.mp4
Finally I went with the Smooth Streaming protocol support (which is a lot more reliable than RTMP).
ffmpeg -i /dev/video1 -pix_fmt yuv420p -f ismv -movflags isml+frag_keyframe -video_track_timescale 10000000 -frag_duration 2000000 -framerate 30 -r 30 -c:v h264_omx -preset ultrafast -map 0:v:0 -b:v:0 2000k -minrate:v:0 2000k -maxrate:v:0 2000k -bufsize 2500k -s:v:0 640x360 -map 0:v:0 -b:v:1 500k -minrate:v:1 500k -maxrate:v:1 500k -s:v:1 480x360 -g 60 -keyint_min 60 -sc_threshold 0 -c:a libfaac -ab 48k -map 0:a? -threads 0 "http://***your-account-***channel.mediaservices.windows.net/ingest.isml/Streams(video)"
DEEP EXPLANATION OF WHAT IS GOING ON ABOVE ON THE FFMPEG COMMAND LINE:
ffmpeg
-re **READ INPUT AT NATIVE FRAMERATE
-stream_loop -1 **LOOP INFINITE
-i C:\Video\tears_of_steel_1080p.mov **INPUT FILE IS THIS MOV FILE
-movflags isml+frag_keyframe **OUTPUT IS SMOOTH STREAMING THIS SETS THE FLAGS
-f ismv **OUTPUT ISMV SMOOTH
-threads 0 ** SETS THE THREAD COUNT TO USE FOR ALL STREAMS. YOU CAN USE A STREAM SPECIFIC COUNT AS WELL
-c:a aac ** SET TO AAC CODEC
-ac 2 ** SET THE OUTPUT TO STEREO
-b:a 64k ** SET THE BITRATE FOR THE AUDIO
-c:v libx264 ** SET THE VIDEO CODEC
-preset fast ** USE THE FAST PRESET FOR X246
-profile:v main **USE THE MAIN PROFILE
-g 48 ** GOP SIZE IS 48 frames
-keyint_min 48 ** KEY INTERVAL IS SET TO 48 FRAMES
-sc_threshold 0 ** NOT SURE!
-map 0:v ** MAP THE FIRST VIDEO TRACK OF THE FIRST INPUT FILE
-b:v:0 5000k **SET THE OUTPUT TRACK 0 BITRATE
-minrate:v:0 5000k ** SET OUTPUT TRACK 0 MIN RATE TO SIMULATE CBR
-maxrate:v:0 5000k ** SET OUTPUT TRACK 0 MAX RATE TO SIMULATE CBR
-s:v:0 1920x1080 **SCALE THE OUTPUT OF TRACK 0 to 1920x1080.
-map 0:v ** MAP THE FIRST VIDEO TRACK OF THE FIRST INPUT FILE
-b:v:1 3000k ** SET THE OUTPUT TRACK 1 BITRATE TO 3Mbps
-minrate:v:1 3000k -maxrate:v:1 3000k ** SET THE MIN AND MAX RATE TO SIMULATE CBR OUTPU
-s:v:1 1280x720 ** SCALE THE OUTPUT OF TRACK 1 to 1280x720
-map 0:v -b:v:2 1800k ** REPEAT THE ABOVE STEPS FOR THE REST OF THE OUTPUT TRACKS
-minrate:v:2 1800k -maxrate:v:2 1800k -s:v:2 854x480
-map 0:v -b:v:3 1000k -minrate:v:3 1000k -maxrate:v:3 1000k -s:v:3 640x480
-map 0:v -b:v:4 600k -minrate:v:4 600k -maxrate:v:4 600k -s:v:4 480x360
-map 0:a:0 ** FINALLY TAKE THE SOURCE AUDIO FROM THE FIRST SOURCE AUDIO TRACK.
 http://<yourchannel>.channel.mediaservices.windows.net/ingest.isml/Streams(stream0)
Hope that helps get you started in the right direction. Let me know if you have any more questions.

Sample accurate audio slicing in ffmpeg?

I need to slice an audio file in .wav format into 10 second chunks.
These chunks need to be exactly 10 seconds, not 10.04799988232 seconds.
the current code I am using is
ffmpeg -i test.wav -ss 0 -to 10 -c:a libfdk_aac -b:a 80k aac/test.aac
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --disable-lzma --enable-nonfree --enable-vda
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from '/Users/chris/Repos/mithc/client/assets/audio/wav/test.wav':
Duration: 00:04:37.62, bitrate: 2307 kb/s
Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s32 (24 bit), 2304 kb/s
Output #0, adts, to '/Users/chris/Repos/mithc/client/assets/audio/aac/test.aac':
Metadata:
encoder : Lavf57.56.100
Stream #0:0: Audio: aac (libfdk_aac), 48000 Hz, stereo, s16, 80 kb/s
Metadata:
encoder : Lavc57.64.101 libfdk_aac
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s24le (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
size= 148kB time=00:00:15.01 bitrate= 80.6kbits/s speed=40.9x
video:0kB audio:148kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
This code does not produce exact slices, any ideas how can this be accomplished?
Not possible*. AAC audio is stored in frames which decode to 1024 samples. So, for a 48000 Hz feed, each frame has a duration of 0.02133 seconds.
If you store the audio in a container like M4A which indicates duration per-packet, the duration of the last frame is adjusted to satisfy the specified t/ss-to. But the last frame still contains the full 1024 samples. See the readout below of the last 3 frames of a silent stream specified to be 10 seconds in a M4A. Compare the packet size(s) vis-a-vis the duration.
stream #0:
keyframe=1
duration=0.021
dts=9.941 pts=9.941
size=213
stream #0:
keyframe=1
duration=0.021
dts=9.963 pts=9.963
size=213
stream #0:
keyframe=1
duration=0.016
dts=9.984 pts=9.984
size=214
If this stream were originally stored in .aac, total duration would not be 10.00 seconds. Now whether M4A does the trick for you will depend on your player.
*there is a variant of AAC which decodes to 960 samples. So, a 48 kHz audio could be encoded to a stream exactly 10 seconds long. FFmpeg does not sport such an AAC encoder. AFAIK, many apps including itunes will not play such a file correctly. If you want to encode to this spec, there's an encoder available at https://github.com/Opendigitalradio/ODR-AudioEnc

Merging video and audio stream, where audio drifts

I want to record audio and video with my raspberry pi b+ 2.
I tried to accomplish this with one ffmpeg command but this is to slow. and i could not get it working correctly
I have a raspberry pi camera module and a Cirrus audio card. On the raspberry i have compiled a new kernel with support for the audio card. I also compiled ffmpeg on the raspberr with alsa support
~$ ffmpeg
ffmpeg version N-71470-g2db24cf Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.6 (Debian 4.6.3-14+rpi1)
configuration: --arch=armel --target-os=linux --enable-gpl --extra-libs=-lasound --enable-nonfree
libavutil 54. 22.101 / 54. 22.101
libavcodec 56. 34.100 / 56. 34.100
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Now i try to record an audio stream and a video stream 'at the same time'
I do this my running a shell script
raspivid -t 60000 -vs -w 1280 -h 720 -b 5000000 -fps 25 -o video.h264 &
arecord -Dhw:sndrpiwsp -r 44100 -c 2 -d 60 -f S32_LE audio.aac
i also tried with -r 22050 and -f S16_LE
when running this it sometimes gives an (i think)
overrun!!! (at least 1038.725 ms long)
at the end of the script i have two files. a video and a audio file.
now i want to merge those two together by using ffmpeg
ffmpeg -i video.h264 -i audio.aac -c:v copy -c:a aac -strict experimental output.mp4
this gives the output:
ffmpeg version N-71470-g2db24cf Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.6 (Debian 4.6.3-14+rpi1)
configuration: --arch=armel --target-os=linux --enable-gpl --extra-libs=-lasound --enable-nonfree
libavutil 54. 22.101 / 54. 22.101
libavcodec 56. 34.100 / 56. 34.100
libavformat 56. 30.100 / 56. 30.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 14.100 / 5. 14.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, h264, from 'video_1min_3.h264':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p, 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from 'audio_1min_3.aac':
Duration: 00:01:00.00, bitrate: 705 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, 2 channels, s16, 705 kb/s
[mp4 # 0x3230f20] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, mp4, to 'output_1min_3.mp4':
Metadata:
encoder : Lavf56.30.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 25 fps, 25 tbr, 1200k tbn, 1200k tbc
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 22050 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc56.34.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 1822 fps=310 q=-1.0 Lsize= 33269kB time=00:01:12.84 bitrate=3741.7kbits/s
video:32300kB audio:941kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.086073%
so finally i have a file output.mp4 that is a movie with audio that is in sync at the beginning but drifts away to a difference of about 4 seconds. where the audio is ahead of the video.
I hope you can help me trying to solve this issue so the audio does not drift away anymore.
Thanks in advance
( i tried to be as clear as possible )
We can try to use the -async and -vsync options to correct the audio and video time shift.
for example, i have used the below option to reduce the time lag of 2 sec seen in the audio.
./ffmpeg -async 1 -i "weatherinput.mov" -strict -2 -vcodec libx264 -movflags +faststart -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -threads 0 -b:a 128k -pix_fmt yuv420p "weatheroutput.mp4"
Also we can use vsync options if required apart from the ioffset.
The link below can also referred for other combination of using th async, vsync and i offset to avoid the drift.

Crossdevice encoding static file to stream in browser using FFMPEG (segmented h264 ?)

I'm building a mediacenter application in NodeJS which is going pretty ok.
(you can check it out on Github: https://github.com/jansmolders86/mediacenterjs )
I'm using FFMPEG to transcode local (static) movies to a stream which I then send to the browser.
At first I used h264 with Flash which worked in browsers, but I really need it to work on Android an iOS (so no Flash) and preferably working on a Raspberry Pi.
But getting it to play on all devices is driving me absolutely insane!
I have all these bits of the puzzle I've gathered from countless hours reading articles, tutorials and stack overflow posts, which led me to the conclusion that I need to produce the following:
Use video codec H264 to transcode to MP4
Move the moovatom '-movflags' to make a MP4 streamable
Segment the stream so Apple can play the stream as well.
But getting nowhere with this. Every time I produce a series of FFMPEG settings that either don't work, or work on some devices rather than all.
Some of my failed attempt where:
My flash attempt -> Main problem (not running in IOS):
'-y','-ss 0','-b 800k','-vcodec libx264','-acodec mp3'\
'-ab 128','-ar 44100','-bufsize 62000', '-maxrate 620k'\
metaDuration,tDuration,'-f flv
my HLS attempt -> Main problem (not running in browser):
'-r 15','-b:v 128k','-c:v libx264','-x264opts level=41'\
'-threads 4','-s 640x480','-map 0:v','-map 0:a:0','-c:a mp3'\
'-b:a 160000','-ac 2','-f hls','-hls_time 10','-hls_list_size 6'\
'-hls_wrap 18','-start_number 1'
My MP4 attempt -> Main problem (duration is shortened and the later part of the video is speeding by)
'-y','-ss 0','-b 800k','-vcodec libx264','-acodec mp3'\
'-ab 128','-ar 44100','-bufsize 62000', '-maxrate 620k'\
metaDuration,tDuration,'-f mp4','-movflags','frag_keyframe+empty_moov'
Second MP4 attempt: -> Main problem (duration is shortened and the later part of the video is speeding by)
'-y','-vcodec libx264','-pix_fmt yuv420p','-b 1200k','-flags +loop+mv4'\
'-cmp 256','-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8'\
'-me_method hex','-subq 7','-trellis 1','-refs 5','-bf 3','-coder 1'\
'-me_range 16','-g 150','-keyint_min 25','-sc_threshold 40'\
'-i_qfactor 0.71','-acodec mp3','-qmin 10','-qdiff 4','-qmax 51'\
'-ab 128k','-ar 44100','-threads 2','-f mp4','-movflags','frag_keyframe+empty_moov'])
Here is an example of the FFMPEG log running with these settings:
file conversion error ffmpeg version N-52458-gaa96439 Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 24 2013 22:19:32 with gcc 4.8.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --e
nable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable
-libgsm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --ena
ble-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwola
me --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enabl
e-libxvid --enable-zlib
libavutil 52. 27.101 / 52. 27.101
libavcodec 55. 6.100 / 55. 6.100
libavformat 55. 3.100 / 55. 3.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 60.101 / 3. 60.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
[avi # 02427900] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'C:/temp/the avengers.avi':
Duration: 00:00:34.00, start: 0.000000, bitrate: 1433 kb/s
Stream #0:0: Video: cinepak (cvid / 0x64697663), rgb24, 320x240, 15 tbr, 15 tbn, 15 tbc
Stream #0:1: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 22050 Hz, mono, u8, 176 kb/s
Please use -b:a or -b:v, -b is ambiguous
[libx264 # 02527c60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 # 02527c60] profile High, level 2.0
[libx264 # 02527c60] 264 - core 130 r2274 c832fe9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x26
4.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x133 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16
chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=2 lookahead_threads=1 sliced_th
reads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 we
ightb=1 open_gop=0 weightp=2 keyint=150 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=120
0 ratetol=1.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00
Output #0, mp4, to 'pipe:1':
Metadata:
encoder : Lavf55.3.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 320x240, q=10-51, 1200 kb/s, 15360 tbn, 15 tbc
Stream #0:1: Audio: mp3 (i[0][0][0] / 0x0069), 44100 Hz, mono, s16p, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (cinepak -> libx264)
Stream #0:1 -> #0:1 (pcm_u8 -> libmp3lame)
Press [q] to stop, [?] for help
frame= 106 fps=0.0 q=10.0 size= 1kB time=00:00:06.94 bitrate= 1.4kbits/s
frame= 150 fps=149 q=14.0 size= 1kB time=00:00:09.87 bitrate= 1.0kbits/s
frame= 191 fps=126 q=16.0 size= 1kB time=00:00:12.61 bitrate= 0.8kbits/s
frame= 244 fps=121 q=16.0 size= 2262kB time=00:00:16.14 bitrate=1147.6kbits/s
frame= 303 fps=120 q=14.0 size= 2262kB time=00:00:20.08 bitrate= 922.2kbits/s
frame= 354 fps=117 q=15.0 size= 3035kB time=00:00:23.48 bitrate=1058.6kbits/s
frame= 402 fps=113 q=15.0 size= 3035kB time=00:00:26.67 bitrate= 932.1kbits/s
frame= 459 fps=113 q=16.0 size= 4041kB time=00:00:30.43 bitrate=1087.7kbits/s
frame= 510 fps=103 q=2686559.0 Lsize= 5755kB time=00:00:33.93 bitrate=1389.3kbits/s
video:5211kB audio:531kB subtitle:0 global headers:0kB muxing overhead 0.235111%
[libx264 # 02527c60] frame I:6 Avg QP:10.55 size: 25921
[libx264 # 02527c60] frame P:245 Avg QP:12.15 size: 14543
[libx264 # 02527c60] frame B:259 Avg QP:15.55 size: 6242
[libx264 # 02527c60] consecutive B-frames: 6.1% 73.7% 14.7% 5.5%
[libx264 # 02527c60] mb I I16..4: 19.9% 6.2% 73.9%
[libx264 # 02527c60] mb P I16..4: 6.0% 0.2% 12.0% P16..4: 35.4% 9.6% 16.3% 7.0% 5.6% skip: 7.8%
[libx264 # 02527c60] mb B I16..4: 0.7% 0.0% 4.3% B16..8: 27.6% 17.2% 17.0% direct:17.3% skip:15.9% L0:39.4% L1:43.2%
BI:17.4%
[libx264 # 02527c60] final ratefactor: 11.41
[libx264 # 02527c60] 8x8 transform intra:1.6% inter:4.0%
[libx264 # 02527c60] coded y,uvDC,uvAC intra: 93.0% 97.0% 94.9% inter: 58.4% 58.7% 50.6%
[libx264 # 02527c60] i16 v,h,dc,p: 15% 26% 54% 5%
[libx264 # 02527c60] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 17% 39% 4% 4% 3% 1% 6% 9%
[libx264 # 02527c60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 34% 21% 4% 2% 2% 2% 2% 5%
[libx264 # 02527c60] i8c dc,h,v,p: 51% 24% 19% 6%
[libx264 # 02527c60] Weighted P-Frames: Y:4.1% UV:1.2%
[libx264 # 02527c60] ref P L0: 68.2% 9.8% 11.0% 5.6% 4.6% 0.8% 0.0%
[libx264 # 02527c60] ref B L0: 87.7% 8.0% 3.9% 0.4%
[libx264 # 02527c60] ref B L1: 97.8% 2.2%
[libx264 # 02527c60] kb/s:1255.36
Lastly this is my node code fireing up FFMPEG. (I use the module Fluent-ffmpeg: https://github.com/schaermu/node-fluent-ffmpeg )
var proc = new ffmpeg({ source: movie, nolog: true, timeout:15000})
.addOptions(['-r 15','-b:v 128k','-c:v libx264','-x264opts level=41','-threads 4','-s 640x480','-map 0:v','-map 0:a:0','-c:a mp3','-b:a 160000','-ac 2','-f hls','-hls_time 10','-hls_list_size 6','-hls_wrap 18','-start_number 1 stream.m3u8'])
.writeToStream(res, function(retcode, error){
if (!error){
console.log('file has been converted succesfully',retcode .green);
}else{
console.log('file conversion error',error .red);
}
});
So to conclude this very long and code heavy question:
I hope this does not come off as a lazy request, but could someone show/explain to me which FFMPEG settings could/should work on all platforms (modern browsers, Android and iOS) producing a stream of a static file which I can send to a HTML5 player.
[EDIT] what I need if a generic option isn't available
And if this is not possible as some posts might suggest, I would love to see a set of FFMPEG settings that get's the job done properly as far as mp4 streaming is concerned. (e.g encoding a streamable mp4).
The streaming mp4 needs the following
A shifted moovAtom
It needs to be h264
Thanks very much for your help!
There is no format that can play on every device and browser. HTML5 is getting us closer, but there is still debate on formats and codecs. My friends at Zencoder have a new blog post blog post (HERE) that addresses this exact issue.
EDIT: you asked for more specifics. Again, it depends on what platforms you wish to target. I will cover a couple here.
This should play on all modern browsers that support the h.264 codec. It should also play on iPhone4 and above:
ffmpeg -i ~/Dropbox/Test\ Content/bigbuckbunny/bigbuckbunny_1500.mp4 -vcodec libx264 -profile:v main -b:v 512k -s 1280x720 -r:v 30 -acodec libfdk_aac -b:a 128k -movflags faststart -y movie1.mp4
The iPhone 3gs does not support main profile, and its max supported resolution is 640x480. This command will encode for this older device.
ffmpeg -i ~/Dropbox/Test\ Content/bigbuckbunny/bigbuckbunny_1500.mp4 -vcodec libx264 -profile:v baseline -b:v 512k -s 640x432 -r:v 30 -acodec libfdk_aac -b:a 128k -movflags faststart -y movie2.mp4
I encoded some sample files and created a web page here:
http://szatmary.org/stackoverflow/18758133/
The HTML looks like this:
<!DOCTYPE html>
<html>
<body>
<br>ffmpeg -i ~/Dropbox/Test\ Content/bigbuckbunny/bigbuckbunny_1500.mp4 -vcodec libx264 -profile:v main -b:v 512k -s 1280x720 -r:v 30 -acodec libfdk_aac -b:a 128k -movflags faststart -y movie1.mp4<br>
<video controls>
<source src="movie1.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<br>ffmpeg -i ~/Dropbox/Test\ Content/bigbuckbunny/bigbuckbunny_1500.mp4 -vcodec libx264 -profile:v baseline -b:v 512k -s 640x432 -r:v 30 -acodec libfdk_aac -b:a 128k -movflags faststart -y movie2.mp4<br>
<video controls>
<source src="movie2.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>
Here the command broken down into what each element means:
command + input file (should be obvious):
ffmpeg -i ~/Dropbox/Test\ Content/bigbuckbunny/bigbuckbunny_1500.mp4
Use libx264 to encode the video:
-vcodec libx264
Set the h.264 profile to main. baseline will allow for playback on older devices, but you will sacrifice a little quality:
-profile:v main
Set the bitrate to 512 kilobits per second. Choose a value based on the available bandwidth. Higher for LAN/WiFi, lower for 3G/LTE
-b:v 512k
Scale the video to 720p resolution (Again depends on target platform)
-s 1280x720
Encode at 30 frames per second:
-r:v 30
Use libfdk_aac to encode the audio. Or use libmp3lame if you want mp3. AAC is highly recommended. It has much better support on ios and produces higher quality audio:
-acodec libfdk_aac
Set audio bitrate to 128 kilobits per second. You may adjust this for bandwidth as well. with AAC you can probably go as low as 32k
-b:a 128k
Set audio sampling rate to 48000 sample per second. If using mp3, do 44100 for ios
-r:a 48000
This tells ffmpeg to place the moov atom at be start of the mp4 file.
-movflags faststart
Output file (-y tells ffmpeg it can overwrite the file without asking)
-y movie1.mp4
As far as I know you won't find a setting which works on every device. I'd recommend you to check the user agent and then use different settings for different devices. This way you could also use device optimized settings.
I'm thinking about 2 workarounds to enable seeking. I'm assuming that, like me, you don't want to store files transcoded in advance.
The first one is just faking seek from the browser. Use a custom timeline control and when seeking change the video src to an URL including the desired start time, and pass it to ffmpeg. Of course this completely defeats browser prefetching. I implemented this in my project and it works fine.
The second option is a bit more technical and I'm not sure how to do it. The idea would be to transcode all available videos in advance, extract the moov atom, save it to disk and write it manually when streaming. This seems quite hard to do but not impossible.

Resources