m1gin 391

#ffmpeg #ubuntu #createvideofromaudio #mp3video #bashscript

Bir MP3 dosyası ve bir PNG dosyası kullanarak bir video dosyası oluşturup bunu youtube üzerine yüklemek mümkün.

Normal şartlarda tek bir resim kullanılarak oluşturulacak video dosyasını üretmek, videonun uzunluğuna ve bilgisayarın performansına bağlı olarak ciddi bir zaman alabilmektedir. Ancak ffmpeg komut satırı uygulamasını kullanarak çok hızlı bir biçimde ve çok küçük boyutta bir video dosyası oluşturmak mümkündür. Üstelik MP3 dosyası da yeniden dönüştürülmeden, orijinal kalitede kullanılır.

Bununla birlikte oluşturulacak bu video dosyasının biraz hileli olduğunu belirtmem gerek. Zira sabit resim dosyası kullanıldığı için onu saniyede 25 kere yinelemek yerine, birkaç saniyede bir yineletsek de görüntü açısından bir değişiklik olmayacaktır. Öte yandan Youtube üzerine yüklenen videolar yeniden işlendiği için, o esnada normal video üretilmiş olmaktadır.

Gereken uygulamar Ubuntu 18.04 ortamında şu şekilde kurulabilir.

  • sudo apt install ffmpeg

Aşağıdaki komutla videoyu oluşturan script, daha sonra her taraftan erişilebilsin diye PATH içerisinde bulunan ~/bin klasörüne indirilir ve çalışma izni verilir.

  • mkdir ~/bin
  • wget "https://mim.mbirgin.com/upload/files/mbirgin_create_video.sh" -O "~/bin/mbirgin_create_video.sh"
  • chmod +x ~/bin/mbirgin_create_video.sh

Kullanım:

  • mbirgin_create_video.sh  "PNG_Konumu" "MP3_Konumu

Video, MP3 dosyasının bulunduğu yere oluşturulur.

Örnek:

  • mbirgin_create_video.sh "/media/data/test/background.png"  "Enlem_ve_Boylam.mp3"

Bir klasördeki tüm mp3 dosyalarını otomatik olarak videoya dönüştürmek de mümkün:

  • for f in *.mp3; do mbirgin_create_video.sh "/media/data/test/background.png" "$f"; done;


Script dosyası içeriği

#!/bin/bash

png="$1";
mp3="$2";

echo "PNG ve MP3 dosyalarından video oluşturan bir uygulamadır."
echo "Kullanım: script PNG MP3"
echo "PNG: $png" 
echo "MP3: $mp3"

if [ ! -f "$mp3" ]; then
    echo "Dosya bulunamadı: $mp3";
    exit
fi

if [ ! -f "$png" ]; then
    echo "Dosya bulunamadı: $png";
    exit
fi

sec=$(ffprobe -v error -show_entries format=duration   -of default=noprint_wrappers=1:nokey=1 "$mp3");
sec=$(echo "$sec/1.0" | bc);

minute=$(( $sec/60 ));
remainder=$(( $sec % 60 ));
echo minute: $minute - remainder: $remainder

echo "Ses süresi (sn):  $sec";

avi="$mp3.avi";

ffmpeg -f concat -safe 0 -i <( echo "file $png"; echo "duration 0.1"; for (( l=0; l<$minute; l++ )); do echo "file $png"; echo "duration 60"; done; for (( k=0; k<=$remainder; k++ )); do echo "file $png"; echo "duration 1"; done; ) -i "$mp3" -c:a copy -map 0:v -map 1:a -shortest  "$avi"

echo "'$avi' oluşturuldu."
echo ""
echo "Tool version: 2019.01.02 by mbirgin.com"

m1gin 0

create video from a list of PNG or SVG files

  • ffmpeg -f concat -i ffconcat.txt -i /test/Extraordinary_English_Podcast/EEP-2.mp3 -s 4096x2304 -acodec copy -shortest eep2.avi

ffconcat.txt content is like:

file cover1.svg
duration 217.65
file cover2.svg
duration 22.14
file f4t_logo.svg
duration 21.31
file cover2.svg
duration 35.63
file f4t_home.svg
duration 10
file f4t_dialog.svg
duration 14.49
file cover2.svg
duration 22.02

Creating Video from SVG images and FLAC audio

creating a video from FLAC audio caused a big file size. 800MB for 12 minutes... here is a trick to make it small:

First create the video using mp3 audio... Then use the video part of the result and combine it with the FLAC audio.

The video with the FLAC audio will be around 70 MB. The flac file itself is already 62 MB.

  1. ffmpeg -f concat -i ffconcat.txt -i /test/Extraordinary_English_Podcast/EEP-2.mp3 -s 4096x2304 -acodec copy -shortest vidmp3.avi
  2. ffmpeg -i /test/Extraordinary_English_Podcast/EEP-2.flac -i vidmp3.avi -map 0:a -map 1:v -vcodec copy -acodec copy -shortest vidflac.mkv

Note that this video needs to be processed. But if it will be uploaded on Youtube it will be fine.

Add to: