Hello guys,
in my app i want to convert active storage attachment video each time we upload one.
In my rails 7 app i'm using
ruby 3.2.2
"rails", "~> 7.1.3.1"
streamio-ffmpeg 3.0.2
ffmpeg version 5.1.5-0+deb12u1 (install on server with dockerfile)
This is how in dockerfile i install ffmpeg
# Install packages needed for deployment
RUN apt-get install --allow-unauthenticated --no-install-recommends -y curl libvips postgresql-client imagemagick ffmpeg libfontconfig && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
This is the content of the convert_video_to_mp4 job looks like
class ConvertVideoToMp4Job < ApplicationJob
queue_as :video_conversion
def perform(attachment)
if attachment.blob.content_type != "video/mp4"
begin
file_name = attachment.blob.filename
Rails.logger.debug { "Converting #{file_name} to MP4..." }
Rails.logger.info("Converting #{file_name} to MP4...")
attachment.blob.open do |tempfile|
movie = FFMPEG::Movie.new(tempfile.path)
path = "tmp/video-#{SecureRandom.alphanumeric(12)}.mp4"
Rails.logger.info("Transcoding video ...")
movie.transcode(path, {video_codec: "libx264", audio_codec: "aac"}) do |progress|
puts "#{(progress * 100).round(1)} %"
end
Rails.logger.info("Conversion of #{file_name} to MP4 is complete.")
Rails.logger.info("Saving new attachment")
attachment.record.attachment.attach(
io: File.open(path),
filename: "#{attachment.name}.mp4",
content_type: "video/mp4"
)
end
rescue => e
Rails.logger.debug "======================================================="
Rails.logger.debug e.message
Rails.logger.error("Error converting #{file_name} to MP4: #{e.message}")
end
end
end
end
It keeps failing. I can't convert any video
[2024-08-14T14:36:05.373281 #698] INFO -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] Performing ConvertVideoToMp4Job (Job ID: bc9bc4d7-9a40-4d35-9ac0-330cc25e0442) from GoodJob(video_conversion) with arguments: #<GlobalID:0x00007f65830753b0 @uri=#<URI::GID gid://followyourmodels/ActiveStorage::Attachment/968a4970-c59c-44ef-98aa-c83408da28cc>>
I, [2024-08-14T14:36:05.384479 #698] INFO -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] Converting IMG_5224.mov to MP4...
I, [2024-08-14T14:36:06.946536 #698] INFO -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] S3 Storage (1559.5ms) Downloaded file from key: 9yy1ffak3vk00wxz4hywmqiuu7ff
I, [2024-08-14T14:36:07.511719 #698] INFO -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] Transcoding video ...
I, [2024-08-14T14:36:07.512622 #698] INFO -- : Running transcoding...
["/usr/bin/ffmpeg", "-y", "-i", "/tmp/ActiveStorage-2587e991-aced-43e5-b605-b1f88225b966-20240814-698-abp6bi.mov", "-vcodec", "libx264", "-acodec", "aac", "tmp/video-cLBEHggXpEjt.mp4"]
0.0 %
E, [2024-08-14T14:36:07.624725 #698] ERROR -- : Failed encoding...
["/usr/bin/ffmpeg", "-y", "-i", "/tmp/ActiveStorage-2587e991-aced-43e5-b605-b1f88225b966-20240814-698-abp6bi.mov", "-vcodec", "libx264", "-acodec", "aac", "tmp/video-cLBEHggXpEjt.mp4"]
ffmpeg version 5.1.5-0+deb12u1 Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 12 (Debian 12.2.0-14)
configuration: --prefix=/usr --extra-version=0+deb12u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enabl
e-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --e
nable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshi
ne --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 -
-enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-libjxl --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559dbe6a3dc0] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559dbe6a3dc0] moov atom not found
/tmp/ActiveStorage-2587e991-aced-43e5-b605-b1f88225b966-20240814-698-abp6bi.mov: Invalid data found when processing input
Errors: no output file created.
E, [2024-08-14T14:36:07.625328 #698] ERROR -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] Error converting IMG_5224.mov to MP4: Failed encoding.Errors: no output file created. Full output: ffmpeg version 5.1.5-0+deb12u1 Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 12 (Debian 12.2.0-14)
configuration: --prefix=/usr --extra-version=0+deb12u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enabl
e-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --e
nable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshi
ne --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 -
-enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-libjxl --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559dbe6a3dc0] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559dbe6a3dc0] moov atom not found
/tmp/ActiveStorage-2587e991-aced-43e5-b605-b1f88225b966-20240814-698-abp6bi.mov: Invalid data found when processing input
I, [2024-08-14T14:36:07.625646 #698] INFO -- : [ActiveJob] [ConvertVideoToMp4Job] [bc9bc4d7-9a40-4d35-9ac0-330cc25e0442] Performed ConvertVideoToMp4Job (Job ID: bc9bc4d7-9a40-4d35-9ac0-330cc25e0442) from GoodJob(video_conversion) in 2252.92ms