FFMPEG::Error on Uploading Video to production - ruby-on-rails

I am currently developing an app which involves uploading video to the server. The video is on .MOV format since it comes from an iOS Device. I have set-up FFMPEG on the server already. But everytime I try to upload a video, an FFMPEG error comes out:
FFMPEG::Error (Failed encoding.Errors: encoded file is invalid. Full output: ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Oct 26 2015 08:48:47 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-gpl --enable-version3 --enable-shared --enable-nonfree --enable-postproc
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/deploy/production/pinoymobiledirectory-ws/public/uploads/tmp/20151029-0424-12438-7062/tmpfile':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2015-10-29 04:24:11
Duration: 00:00:05.38, start: 0.000000, bitrate: 784 kb/s
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s
Metadata:
creation_time : 2015-10-29 04:24:11
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x360, 715 kb/s, 30.11 fps, 29.97 tbr, 600 tbn, 1200 tbc
Metadata:
rotate : 90
creation_time : 2015-10-29 04:24:11
handler_name : Core Media Data Handler
[aac # 0x143c980] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
):
lib/carrierwave/ffmpeg.rb:19:in encode_video'
app/controllers/v1/businesses_assets_controller.rb:33:inupload_video'
Anyone who also got the same error as mine? How did you solved it?

The key part of the message is 'The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it'.
You need to add this flag to your ffmpeg command. For example the following command, which will compress an mp4 video, contains this flag:
ffmpeg -i BigBuckBunny_320x180.mp4 -strict experimental -acodec aac CompressedBBB_320x180_aac.mp4

Fixed it by installing the latest FFMPEG.
Followed this guide: https://gist.github.com/xdamman/e4f713c8cd1a389a5917

Related

iTunesConnect: "One or more of your app previews could not be loaded. Try again."

Problem
Recently I uploaded App preview video to my app in iTunesConnect
It looks like it was uploaded successfully, I was able to play it but there was a text overlay on the video preview:
Processing App Preview
The app preview can take up to 24 hours to process.
I have closed Safari and go to sleep. Next morning I see this
Questions
How can I get a reason why this happens, as far as I see my video conform to https://help.apple.com/app-store-connect/#/dev4e413fcb8 , here is ffprobe output for it
ffprobe version 4.1.4 Copyright (c) 2007-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/camobap/my_video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:30.04, start: 0.000000, bitrate: 1512 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 886x1920, 1377 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : ?Mainconcept Video Media Handler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s (default)
Metadata:
handler_name : #Mainconcept MP4 Sound Media Handler
Who actually does this video review? Humans or machines?
Is there any automation script to do this validation before upload?
Silly me, looks like 24 hours wasn't passed, once I waited more time this problem just gone
P.S. only Safari show this, there is no error in Google Chrome
P.P.S sometimes it happens even for successfully processed video but after a page refresh, the problem is gone

How to extract 16-bit PNG frame from lossless x264 video

I encoded a series of 16-bit grayscale PNGs to a lossless video with the following command:
ffmpeg -i image%04d.png -crf 0 -c:v libx264 -preset veryslow output.mp4
I am now trying to verify that the conversion to video was truly lossless by pulling out the PNGs at the same quality. The command I'm using:
ffmpeg -i output.mp4 image%04d.png
However, this is outputting 8-bit PNGs. I've tried various options I've read about such as -vcodec png and -qscale 0 but so far nothing appears to make it output 16-bit PNGs.
How do I extract all frames from the video at the same quality as they were going in? Or did I make a mistake in creating the lossless video in the first place?
Edit: I get this error message when trying to use -pix_fmt gray16be.
[swscaler # 0x7fef1a8f0800] deprecated pixel format used, make sure
you did set range correctly
Full output:
ffmpeg -i output.mp4 -pix_fmt gray16be image%04d.png
ffmpeg version 3.3.1 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Duration: 00:00:09.76, start: 0.000000, bitrate: 1337 kb/s
Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuvj444p(pc), 512x512, 1336 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> png (native))
Press [q] to stop, [?] for help
[swscaler # 0x7fef1a8f0800] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'image%04d.png':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Stream #0:0(und): Video: png, gray16be, 512x512, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc57.89.100 png
frame= 244 fps=0.0 q=-0.0 Lsize=N/A time=00:00:09.76 bitrate=N/A speed= 21x
video:4038kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
I'm happy to use a non-ffmpeg solution if there is one.
Your lossless video is 8-bit, as that's what x264 has encoded to. And in any case, x264 does not go above 10-bit (for which you would need a standalone encoder, or a different ffmpeg binary).
-c:v ffv1 is lossless and can encode to 16-bit gray (gray16le) or 16-bit RGB (e.g. rgb48le)
That swscaler line is a warning, not an error. FFmpeg does report the output as 16-bit per channel,
Stream #0:0(und): Video: png, gray16be, 512x512 ...
but you've already lost fidelity with the downgrade of the bit depth when you encoded to H.264.
I'm unclear on what the pixel format of the input PNGs is - RGB with no hint of hue, or a monochannel encoding? I suspect the former, in which case, use
ffmpeg -i image%04d.png -c:v ffv1 output.nut
Then you can do a compare with
ffmpeg -i output.nut -i image%04d.png -filter_complex ssim -f null -
A readout of
SSIM R:1.000000 (inf) G:1.000000 (inf) B:1.000000 (inf) All:1.000000 (inf)
indicates full fidelity.

ffmpeg incorrect duration when converting video to HLS

I'm facing an issue using ffmpeg to convert video, precisely mp4 video => Http Live Streaming (HLS)
Once converted to HLS, the .m3u8 file has a wrong duration (e.g : 20,1s instead of 20.00s), causing bugs when playing it with AVPlayer on iOS.
Playing the video with Safari cause the same issue.
Example :
1) Open Safari
2) Play this video that i've converted
3) Look at the download progression, stopped at 98% cause of wrong duration.
4) When you slide between 98% and 100%, the video player can crash.
EDIT 1 :
I've edited the command line
ffmpeg -i video.mp4 \
-codec copy \
-acodec copy \
-map 0 -f ssegment -g 60 -sc_threshold 0 \
-segment_list playlist.m3u8 \
-segment_list_flags +live \
-segment_time 2 media%05d.ts \
>./log_ffmpeg 2>./log_ffmpeg
LOG :
ffmpeg version 3.1.4-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.1 (Debian 5.4.1-2) 20160904
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr --enable-frei0r --enable-libfribidi --disable-indev=sndio --disable-outdev=sndio --enable-librtmp --enable-libzimg --cc=gcc-5 --disable-ffplay
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
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './Comptes/1/Photos/306/original_video.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp41mp42isom
creation_time : 2016-10-12 14:29:51
Duration: 00:00:20.00, start: 0.000000, bitrate: 1673 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 540x960, 1563 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
creation_time : 2016-10-12 14:29:51
handler_name : Core Media Video
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 101 kb/s (default)
Metadata:
creation_time : 2016-10-12 14:29:51
handler_name : Core Media Audio
[stream_segment,ssegment # 0x652ed80] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Last message repeated 1 times
Output #0, stream_segment,ssegment, to './Comptes/1/Photos/306/media%05d.ts':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp41mp42isom
encoder : Lavf57.41.100
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 540x960, q=2-31, 1563 kb/s, 30 fps, 30 tbr, 90k tbn, 600 tbc (default)
Metadata:
creation_time : 2016-10-12 14:29:51
handler_name : Core Media Video
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, 101 kb/s (default)
Metadata:
creation_time : 2016-10-12 14:29:51
handler_name : Core Media Audio
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 601 fps=0.0 q=-1.0 Lsize=N/A time=00:00:20.10 bitrate=N/A speed= 917x
video:3823kB audio:249kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
m3u8 file :
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:3
#EXTINF:2.033333,
media00000.ts
#EXTINF:2.000000,
media00001.ts
#EXTINF:2.000000,
media00002.ts
#EXTINF:2.000000,
media00003.ts
#EXTINF:2.000000,
media00004.ts
#EXTINF:2.000000,
media00005.ts
#EXTINF:2.000000,
media00006.ts
#EXTINF:2.000000,
media00007.ts
#EXTINF:2.000000,
media00008.ts
#EXTINF:2.000000,
media00009.ts
#EXTINF:0.033333,
media00010.ts
#EXT-X-ENDLIST
As you can see input duration =/= output duration
input duration : 20s
output duration 20.1s

Video Failed to transcode with FFmpeg with Rails app in my localhost

I ve tried to upload videos using Carrierwave-video & FFmpeg. I've installed FFmpeg and there is no problem with installation. I have made configurations from ' http://blog.41studio.com/upload-videos-using-carrierwave-ffmpeg/ ' .But when I tried to upload video (.mov file), I have an error.
Error
Video Failed to transcode with FFmpeg. Check ffmpeg install and verify video is not corrupt or cut short. Original error: Failed encoding.Errors: encoded file is invalid. Full output: ffmpeg version 2.8.3 Copyright (c) 2000-2015 the FFmpeg developers built with Apple LLVM version 7.0.0 (clang-700.1.76) configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.3 --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-libvo-aacenc --enable-libxvid --enable-libfaac --enable-nonfree --enable-vda libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/tanerkoroglu/Desktop/Wishpere2/public/uploads/tmp/1449435556-7186-2107/IMG_1756.MOV': Metadata: major_brand : qt minor_version : 0 compatible_brands: qt creation_time : 2015-10-17 12:19:27 Duration: 00:01:04.24, start: 0.000000, bitrate: 17176 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 17082 kb/s, 29.98 fps, 29.97 tbr, 600 tbn, 1200 tbc (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler encoder : H.264 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 85 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Please use -q:a or -q:v, -qscale is ambiguous [Parsed_movie_0 # 0x7feb6bf00100] Failed to avformat_open_input '/Users/tanerkoroglu/Desktop/Wishpere2/app/assets/images/logo.png' [AVFilterGraph # 0x7feb6bc09240] Error initializing filter 'movie' with args '/Users/tanerkoroglu/Desktop/Wishpere2/app/assets/images/logo.png' Error opening filters!
video_uploader.rb
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
process :encode
def encode
encode_video(:mp4, watermark: {path: File.join(Rails.root, "app/assets/images/logo.png")})
end
version :mp4 do
def full_filename(for_file)
super.chomp(File.extname(super)) + '.mp4'
end
end
end
Gemfile
gem 'carrierwave', '0.10.0'
gem 'carrierwave-video'
gem 'streamio-ffmpeg'
I had the same error. In my case it was because of carrierwave-video is incompatible with streamio-ffmpeg (3.0.2). streamio-ffmpeg expects to receive array of format_params, but carrierwave-video returns a string. I fixed it in my fork

Uploading video error with Carrierwave in Rails

I ve tried to upload videos using Carrierwave-video & FFmpeg. I've installed FFmpeg and there is no problem with installation. I have made configurations (I'm not sure from them) from but when I tried to upload video (.mov file), I have an error.
Please help me to fix this problem with Carrierwave & FFmpeg or please guide to me uploading videos to my app with different ways. (Note: I am using Carrierwave for uploading images to my app, and it works perfect)
Thanks for your attention.
Error
Video Failed to transcode with FFmpeg. Check ffmpeg install and verify video is not corrupt or cut short. Original error: Failed encoding.Errors: encoded file is invalid. Full output: ffmpeg version 2.8.3 Copyright (c) 2000-2015 the FFmpeg developers built with Apple LLVM version 7.0.0 (clang-700.1.76) configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.3 --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-libvo-aacenc --enable-libxvid --enable-libfaac --enable-nonfree --enable-vda libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/tanerkoroglu/Desktop/Wishpere2/public/uploads/tmp/1449435556-7186-2107/IMG_1756.MOV': Metadata: major_brand : qt minor_version : 0 compatible_brands: qt creation_time : 2015-10-17 12:19:27 Duration: 00:01:04.24, start: 0.000000, bitrate: 17176 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 17082 kb/s, 29.98 fps, 29.97 tbr, 600 tbn, 1200 tbc (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler encoder : H.264 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 85 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default) Metadata: creation_time : 2015-10-17 12:19:27 handler_name : Core Media Data Handler Please use -q:a or -q:v, -qscale is ambiguous [Parsed_movie_0 # 0x7feb6bf00100] Failed to avformat_open_input '/Users/tanerkoroglu/Desktop/Wishpere2/app/assets/images/logo.png' [AVFilterGraph # 0x7feb6bc09240] Error initializing filter 'movie' with args '/Users/tanerkoroglu/Desktop/Wishpere2/app/assets/images/logo.png' Error opening filters!
video_uploader.rb
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
process :encode
def encode
encode_video(:mp4, watermark: {path: File.join(Rails.root, "app/assets/images/logo.png")})
end
version :mp4 do
def full_filename(for_file)
super.chomp(File.extname(super)) + '.mp4'
end
end
end
Gemfile
gem 'carrierwave', '0.10.0'
gem 'carrierwave-video'
gem 'streamio-ffmpeg'

Resources