ffmpeg recoded mp4 files error on mobiles in Video JS - ffmpeg

We are converting seriously old .flv files to MP4 with FFMPEG. These are at least 10 years old.
Back then all were rendered with early versions of Adobe Premiere.
On desktop browsers all the files work and stream (...watching them feels like going back a century!)
But when requesting the videos on the same pages on mobile devices (android and ios) Video JS doesn't even show up.
Perhaps the codec is just too old, but I was wondering if there could be another reason when converting them with this line:
for i in *.flv; do ffmpeg -i "$i" "${i%.*}.mp4"; done
If not, is it possible to detect this in Video JS, so we can show an announcement that the video is only visible on desktops?
I hope someone here has this knowledge!
added on request of llogan
ffmpeg version N-78967-gbaec6d8 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4) configuration: --prefix=/root/ffmpeg_build
--extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 libavutil 55. 19.100 / 55. 19.100 libavcodec 57. 28.100 / 57. 28.100 libavformat 57. 28.100 / 57. 28.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 39.102 /
6. 39.102 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a_4293_06.mp4': Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.28.100 Duration: 00:01:40.10, start: 0.023220, bitrate: 492 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240, 376 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 123 kb/s (default)
Metadata:
handler_name : SoundHandler At least one output file must be specified

Thanks to #llogan's comments I can answer this one myself.
First, I upgraded ffmpeg to the latest version, and then did some research on the -movflags and +faststart.
I found a 2015 article with great info on how to convert .flv to .mp4 (https://addpipe.com/blog/flv-to-mp4/)
So, in order to make the new .mp4 files compatible with mobile devices, you need to add a profile and a level, like this:
in a batch convert:
for i in *.flv; do ffmpeg -y -i "$i" -movflags +faststart -profile:v baseline -level 3.0 "${i%.*}.mp4"; done
and for a single file:
ffmpeg -i filename.flv -movflags +faststart -profile:v baseline -level 3.0 filename.mp4
And then the terminal shows this line when converting:
Starting second pass: moving the moov atom to the beginning of the
file
That is needed, but the addition of the -profile and -level actually made the videos work on the mobile devices.

Related

How to compile ffmpeg to get only mp3 and mp4 support

I'm building Electron app and I use ffmpeg to convert m4a or webm files to mp3, and also to merge video only mp4 with m4a audio file to mp4.
I am able to achieve this using [media-autobuild-suite] (https://github.com/jb-alvarado/media-autobuild_suite), using light build option, but the size of static files is arround 20mb and I'would like to shrink it a little bit more. I've compiled ffmpeg and ffprobe with this configuration.
--disable-libaom
--disable-version3
# Full
--disable-chromaprint
--disable-cuda-sdk
--disable-decklink
--disable-frei0r
--disable-libbs2b
--disable-libcaca
--disable-libcdio
--disable-libfdk-aac
--disable-libflite
--disable-libfribidi
--disable-libgme
--disable-libgsm
--disable-libilbc
--disable-libkvazaar
--disable-libmodplug
--disable-libnpp
--disable-libopenh264
--disable-libopenmpt
--disable-librtmp
--disable-librubberband
--disable-libssh
--disable-libtesseract
--disable-libxavs
--disable-libzmq
--disable-libzvbi
--disable-opencl
--disable-opengl
--disable-libvmaf
--disable-libcodec2
--disable-libsrt
--disable-ladspa
--disable-ffplay
#--enable-vapoursynth
#--enable-liblensfun
--disable-libndi_newtek
--enable-demuxer=mp3
--enable-demuxer=mov
--enable-demuxer=opus
--enable-parser=ac3
--enable-parser=mpegaudio
--enable-parser=h264
--enable-parser=opus
--enable-protocol=file
--enable-protocol=pipe
--enable-decoder=mp3
--enable-decoder=mp4
--enable-decoder=opus
--enable-encoder=mp3
--enable-encoder=mp4
--enable-encoder=opus
With this configuration I'm getting ffmpeg static file arround 2mb and ffprobe static file arround 2mb but with this error.
C:\Users\Admin\Desktop\ffmpeg compilations\2mb\local64>ffmpeg -i simple.m4a simple.mp3
ffmpeg version N-93147-g9326117bf6 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 8.2.1 (Rev1, Built by MSYS2 project) 20181214
configuration: .... //here comes configuration as described above
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'simple.m4a':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
creation_time : 2018-10-31T19:47:32.000000Z
Duration: 00:02:38.92, start: 0.000000, bitrate: 127 kb/s
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 7 kb/s (default)
Metadata:
creation_time : 2018-10-31T19:47:32.000000Z
handler_name : SoundHandler
[NULL # 0000000000486200] Unable to find a suitable output format for 'simple.mp3'
simple.mp3: Invalid argument
Any ideas what else should I include into this static file?
No need to disable things piecemeal: just use --disable-everything then enable what you need.
Here's an example you can start out with:
./configure
--disable-everything
--disable-network
--disable-autodetect
--enable-small
--enable-decoder=aac*,ac3*,opus,vorbis
--enable-demuxer=mov,m4v,matroska
--enable-muxer=mp3,mp4
--enable-protocol=file
--enable-libshine
--enable-encoder=libshine
--enable-filter=aresample
Final binary size will be around 2-3 MB.
No need to enable any parsers: the selected decoders will automatically select whichever are required.
FFmpeg does not have a native MP3 encoder, so you'll need to use an external library such as libmp3lame or libshine. Since you mentioned Android I assumed you'll want libshine instead of libmp3lame to encode MP3.
Test thoroughly. I probably forgot something.
If you really want to go nuts then use --disable-all instead of --disable-everything and you'll additionally have to manually include the FFmpeg libraries that you want, but that's more work and more headache for not much return.
This will allow you to encode MP3 audio from most M4A and Webm inputs:
ffmpeg -i input.webm output.mp3
And will also let you re-mux MP4/M4V + M4A into MP4:
ffmpeg -i video.m4v -i audio.m4a -map 0:v -map 0:a -c copy output.mp4

FFMPEG [h264_nvenc # 0x56151389fe00] Cannot get the preset configuration: invalid version (15)

i have issue with ffmpeg as usual :D. I have FFMPEG compiled (version N-90807-g00099ef0d0) with NVIDIA support (latest CUDA and latest NV Headers):
ffmpeg version N-90807-g00099ef0d0 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-libnpp --enable-cuda --enable-cuvid --enable-nvenc --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --enable-gpl --enable-libx264 --disable-x86asm --enable-libx265 --enable-libfdk-aac --enable-nonfree --enable-x86asm
libavutil 56. 15.100 / 56. 15.100
libavcodec 58. 19.100 / 58. 19.100
libavformat 58. 13.100 / 58. 13.100
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 19.100 / 7. 19.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
When I try to run basic transcoding on GPU using command:
ffmpeg -i 'udp://#239.100.0.1:331?fifo_size=‎100000000' -map i:0x100 -g 20 -vcodec h264_nvenc -map i:0x101 -ab 128k -ar 48k -acodec aac -f mpegts udp://#239.0.0.1:1234?overrun_nonfatal_optin=
I got this error:
Input #0, mpegts, from 'udp://#239.100.0.1:331?fifo_size=‎100000000':
Duration: N/A, start: 106.414400, bitrate: N/A
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 # 0x55a5edc45880] co located POCs unavailable
[h264_nvenc # 0x55a5edc45380] Cannot get the preset configuration: invalid version (15)
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
[aac # 0x55a5edc46d40] Qavg: 227.785
[aac # 0x55a5edc46d40] 2 frames left in the queue on closing
I have same version of FFMPEG compiled by the same way on another testing machine and there it is working. I tried to recompile/reinstall ffmpeg with the latest version, but result is the same.
Does someone know what could be wrong on my instance?
Thanks.
Fixed. The issue was in nvidia headers. Used version was extremely new. If you'll get this issue, just use the headers with tag n8.0.14.1 and then compile ffmpeg.
FFmpeg version of headers required to interface with Nvidias codec APIs:
git clone https://github.com/FFmpeg/nv-codec-headers.git
git checkout n8.0.14.1
make && make install

Set fake duration on h264 video

I have a script that fetches multiple chunks of a video from one place and streams it as a single video to other place (to Kodi player).
Everything seems to work fine except one thing that bothers me, the player doesn't seem to know how long the video is, therefore the total duration increments as the video plays.
I do know the duration of the video from an xml file that contains a link to all the chunks, but I don't know how to write that in the metadata of the first chunk.
The video codec is h264, but I'm not sure if it is wrapped in some container, like mp4.
Here is the ffmpeg -i output for the first chunk:
ffmpeg version 3.1.5 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.5 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
[mpegts # 0x7fc3c6000000] start time for stream 0 is not set in estimate_timings_from_pts
Input #0, mpegts, from '/Users/ibra/Desktop/daTgXic4JOI.ts':
Duration: 00:00:17.56, start: 0.000000, bitrate: 1220 kb/s
Program 1
Stream #0:0[0x102]: Data: timed_id3 (ID3 / 0x20334449)
Stream #0:1[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:2[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 150 kb/s
And here is a messy screenshot of the file opened in a hex editor:
https://www.evernote.com/l/AWlILw5PcmVEl4fSFitOfS2M8Wzy1WTVSZc
Any suggestions of how to insert the video duration in the metadata of the first chunk?
I cannot download the all the chunks and then concat in a single file because this will take too much time and the streaming must be instantly.
The container format is mpegts. There is no standard way to encode a duration in mpegts (or h.264 for that matter). So whatever you do will be proprietary. You could write it to the ID3 metaadata, but then kodi would need to be modified to handle this.

FFmpeg 'Unable to parse option value "(null)" as sample format'

Im trying to process a file and run the following command
ffmpeg -i input.webm output.webm
I'm doing it with the ffmpeg library from videoconverter.js. I'm trying to understand what is wrong or how I can fix it.
I end up getting this:
Worker has received command
Received command: -i input.webm output.webm. Processing with 268435456 bits.
ffmpeg version 2.2.1 Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 9 2014 20:24:32 with emcc (Emscripten GCC-like replacement) 1.12.0 (commit 6960d2296299e96d43e694806f5d35799ef8d39c)
configuration: --cc=emcc --prefix=/Users/bgrinstead/Sites/videoconverter.js/build/ffmpeg/../dist --extra-cflags='-I/Users/bgrinstead/Sites/videoconverter.js/build/ffmpeg/../dist/include -v' --enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic --disable-ffplay --disable-ffprobe --disable-ffserver --disable-asm --disable-doc --disable-devices --disable-pthreads --disable-w32threads --disable-network --disable-hwaccels --disable-parsers --disable-bsfs --disable-debug --disable-protocols --disable-indevs --disable-outdevs --enable-protocol=file --enable-libvpx --enable-gpl --extra-libs='/Users/bgrinstead/Sites/videoconverter.js/build/ffmpeg/../dist/lib/libx264.a /Users/bgrinstead/Sites/videoconverter.js/build/ffmpeg/../dist/lib/libvpx.a'
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
[vp8 # 0xed8c00] Warning: not compiled with thread support, using thread emulation
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, matroska,webm, from 'input.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Audio: opus, 48000 Hz, mono (default)
Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
[abuffer # 0xedd670] Unable to parse option value "(null)" as sample format
Last message repeated 1 times
Last message repeated 1 times
[abuffer # 0xedd670] Error setting option sample_fmt to value (null).
[graph 1 input from stream 0:0 # 0xedd600] Error applying options to the filter.
Error opening filters!
Finished processing (took 673ms)
The end result is stopped due to 'Unable to parse option value "(null)" as sample format'. How would I solve this?
Your ffmpeg build is using version 2.2.1 which is old and unsupported.
It is too old to natively support Opus decoding (this version requires libopus to decode Opus). Upgrade to a build derived from the development branch ("git master") or at least use the latest release.
You should also use a modern libvpx if possible as well. Note that with recent FFmpeg you will need to remove --disable-bsfs because VP9 is now the default video encoder for Webm and it requires the vp9_superframe bitstream filter (it is automatically applied). Alternatively, you can force VP8 encoding with -c:v libvpx.
Consider adding libopus (preferred) or libvorbis support for Webm; otherwise you'll be using the very crappy and experimental FFmpeg native Vorbis encoder.

ffmpeg not converting an mp3 on OSX. Homebrew installed. Encoder (codec mp3) not found for output stream #0:0

Ok, did the standard hoembrew install for ffmpeg.
All looks cool, i'm guessing that has to include the mpeg codec, yet I keep getting a 0 byte file and the error message:
Encoder (codec mp3) not found for output stream #0:0
Help most appreciated.
ffmpeg -i input.mp3 -b:a 48k -ar 16000 output.mp3
ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.29)
configuration:
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
[mp3 # 0x7ff05a010600] Skipping 0 bytes of junk at 626.
Input #0, mp3, from 'input.mp3':
Metadata:
title : Allegro from Duet in C Major
Duration: 00:00:59.56, start: 0.025057, bitrate: 192 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
Metadata:
encoder : LAME3.96r
Output #0, mp3, to 'output.mp3':
Metadata:
title : Allegro from Duet in C Major
Stream #0:0: Audio: mp3, 0 channels, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> ? (?))
Encoder (codec mp3) not found for output stream #0:0
This ended up working: brew install --use-clang --HEAD ffmpeg

Resources