m1gin 1188

#ffmpeg #avconv #audioprocess #cli #ubuntu #linux #multimedia #soundeditor

In Ubuntu:

sudo apt-get install ffmpeg libavcodec-extra-53

sudo apt-get install libmp3lame0



Copy audio from mp4 file:

  • ffmpeg -i 4-Bakara_Suresi_28-46.mp4 -acodec copy file.aac

Copy only audio with no video:

  • ffmpeg -i test.webm -vn -acodec copy audio.ogg
  • ffmpeg -i 2.webm -vn -acodec libvorbis -ab 64k -ac 1 -ab 44100 audio2.ogg

-vn for no video. -an is for no audio.

Convert file to mp3

  • ffmpeg -i file.m4a -acodec libmp3lame file.mp3

Convert audio using VBR:

  • ffmpeg -i file.wav -q:a 5 "vbr.mp3"

Mono output: (ac: audio channel)

  • ffmpeg -i file.aac -ac 1 -acodec libmp3lame aac-ac2.mp3

Split stereo channels and save them separateley:

ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav

2 mono input, 1 stereo output:

ffmpeg -i left.mp3 -i right.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map "[a]" output.mka

Convert audio with 16-bit sample depth:

  • ffmpeg -i 2019-10-28.ogg -c:a flac -sample_fmt s16 2019-10-28.flac

To list available sample formats:

  • ffmpeg -sample_fmts

Change bitrate …

  • ffmpeg -i file.aac -ab 128000 -ar 44100 -acodec libmp3lame aac.mp3
  • ffmpeg -i 4-Bakara_Suresi_28-46.mp4 -ac 1 -ab 80000 -ar 44100 -acodec libmp3lame aac.mp3

Cut Audio/Video Part:

  • ffmpeg -ss 00:00:30 -t 00:03:15 -i video.mp4 -vcodec copy -acodec copy cut.mp4
  • ffmpeg -ss 10 -t 95 -i audio.mp3 -acodec copy cut.mp3

Preserve ID3 tags:

  • ffmpeg -i in.flac -ab 320k -map_metadata 0 out.mp3

-map_metadata -1 : clear info.

ID3 Tags

ffmpeg -i in.mp3 -metadata title="Title" -metadata artist="Artis" -metadata album="Album" out.mp3

Some other keys for ID3: album_artist, date (year), copyright, encoded_by, publisher

https://wiki.multimedia.cx/index.php/FFmpeg_Metadata

Using id3v2 command line tool is a good option.



Copy video and make audio mono:

ffmpeg -i 4.flv -ac 1 -vcodec copy 4_copy.flv

List supoorted format:

ffmpeg -formats

Normalize Audio

  • ffmpeg -i test.mp3 -af "dynaudnorm" test_dynaud.mp3
  • ffmpeg -i test.mp3 -af 'atempo=1.5, dynaudnorm=f=500:g=33' -t 120 dynaud.mp3
  • ffmpeg -i "47324.mp3" -filter:a loudnorm -sample_fmt s16 47324.mp3.flac
  • ffmpeg -i test.mp3 -af "loudnorm=i=-16:tp=-1" -ar 44100 -sample_fmt s16 out.flac


Capture live stream

ffmpeg -i http://mediaserver3.akradyo.net/shoutcast/akra.stream/playlist.m3u8 -acodec copy akra_live.mp3



ffmpeg ses/video gecikmesi, bir kısmın alınması gibi işlevlere sahiptir.



Toplu halde dosya dönüştürmek için örnek:

  • for f in *.m4a; do ffmpeg -i "$f" -acodec libmp3lame "${f%.m4a}.mp3"; done
  • for f in *.mp4; do ffmpeg -i "$f" -metadata title="${f%.mp4}" -metadata artist="Mustafa İslamoğlu" -metadata album="Tefsir Dersleri" -metadata album_artist=”www.mbirgin.com” -ac 1 -ab 80000 -ar 44100 -acodec libmp3lame "${f%%-*.mp4}.mp3"; done
  • for f in 1.mp4 2.mkv 3.webm 4.mp4; do ffmpeg -i "http://mbirgin.com/sil/$f" -acodec libmp3lame -ar 44100 -ab 128k "${f%.mp4}.mp3"; done

Rotate video without re-encoding:

  • ffmpeg -i video.mp4 -c copy -metadata:s:v:0 rotate=180 rotated.mp4



# Picking the 30 seconds fragment at an offset of 1 minute:

# In seconds

ffmpeg -i input.mp3 -ss 60 -t 30 output.wav

# In HH:MM:SS format

ffmpeg -i input.mp3 -ss 0:01:00 -t 0:00:30 output.wav

Record Screen with ffmpeg

  • ffmpeg -f alsa -i pulse -f x11grab -r 10 -s 800x600 -i :0.0 -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm
  • avconv -f alsa -i hw:0,0 -f x11grab -b 4000k -r 10 -s 1200x600 -i :0.0+0,20 -vcodec libvpx -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm
  • ffmpeg -f alsa -i hw:0,0 -f x11grab -r 5 -b 2000 -i :0.0 -ar 44100 -ab 64k -ac 1 -threads 0 -vcodec flashsv ./Desktop/mydesktop2.flv

Record full screeen by get resolution automatically:

  • ffmpeg -f alsa -i hw:0,0 -f x11grab -b 3000k -r 10 -s $(xdpyinfo | grep 'dimensions:'|awk '{print $2}') -i :0.0 -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm
  • ffmpeg -f alsa -i pulse -f x11grab -b 4000k -r 10 -s $(xwininfo -root | awk '/geometry/ {print $2}') -i :0.0 -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm
  • ffmpeg -f x11grab -b 2000k -r 8 -s $(xwininfo -root | awk '/geometry/ {print $2}') -i :0.0 -threads 0 screen.mp4



Record a window:

To record a window, we should specify some parameters.

-s widthxheight -i :0.0+left,top

To get the coordinates of a window we can use the command xwininfo
We need: Absolute upper-left X, Absolute upper-left Y, Width, Height

  • xwininfo | grep -e Width -e Height -e Absolute

After clicking on target window the values will shown. We can use ffmpeg to record the window with parameters. For example: -s 923x613 -i :0.0+179,58

  • avconv -f alsa -i hw:0,0 -f x11grab -b 4000k -r 10 -s 923x613 -i :0.0+179,58 -vcodec libvpx -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm



Capture from a webcam:

  • ffmpeg -f alsa -i pulse-f video4linux2 -i /dev/video0 -vb 800k -r 10 -s 640x480 -vcodec libvpx -acodec libvorbis -ar 44100 -ab 64k -ac 1 -threads 0 capture.webm
  • avconv -f alsa -i pulse -f video4linux2 -i /dev/video0 -b 1000k -r 10 -s 640x480 -acodec libmp3lame -ar 44100 -ab 64k -ac 1 capture.mp4
  • avconv -f alsa -i hw:0,0 -f video4linux2 -i /dev/video0 -b 1000k -r 10 -s 640x480 -acodec libvo_aacenc -ar 44100 -ab 64k -ac 1 -threads 0 capture.mp4



Capture Video from IP Webcam Stream

Normalde kayıt hızlı oynatılıp br anda bitiyordu. Ancak -use_wallclock_as_timestamps 1 parametresi eklenince, normalleşti.

  • Ffmpeg -use_wallclock_as_timestamps 1 -f mjpeg -i http://localhost:8090/video -c copy test.avi
  • ffmpeg -use_wallclock_as_timestamps 1 -f mjpeg -i http://localhost:8090/video -c vp8 -vb 500k test.webm





Capture video and play

- instead of input/output file name.

  • ffmpeg -f video4linux2 -s 640x360 -i /dev/video0 test1.webm -f webm - | ffplay -f webm -i -
  • ffmpeg -f alsa -i pulse -f video4linux2 -i /dev/video0 test.webm -f avi - | ffplay -f avi -i -




Follow mouse pointer:

avconv -f x11grab -follow_mouse 100 -r 5 -i :0.0 mydesktop2.webm

avconv -f x11grab -follow_mouse 80 -r 5 -b 1200k -i :0.0 -f alsa -i hw:0,0 -ar 44100 -ab 64k -ac 1 -s 600x400 av.webm

Crop Video:

ffmpeg -i in.avi -vf "crop=352:195:20:100" out.webm

ffmpeg -i capture_2014-01-16_03.avi -t 60 -vf "crop=352:195:0:0" -acodec libvorbis -ab 32k -ac 1 -ab 44100 -vcodec libvpx -vb 400k capture_2014-01-16_03.webm



Record Audio with ffmpeg

  • avconv -f alsa -i pulse -ar 44100 -ab 64k -ac 1 -acodec libmp3lame audio.mp3
  • avconv -f alsa -i hw:0,0 -ar 44100 -ab 64k -ac 1 audio.mp3
  • avconv -f alsa -i hw:0,0 -ar 44100 -ab 64k -ac 1 -acodec libvorbis audio.ogg
  • avconv -f alsa -i hw:0,0 -ar 44100 -ab 64k -ac 1 audio.ogg
  • avconv -f alsa -i hw:0,0 -ar 44100 -ab 64k -ac 1 audio.aac
  • avconv -f alsa -i hw:0,0 -ar 44100 -ac 1 audio.wav
  • avconv -f alsa -i hw:0,0 -acodec wmav2 audio3.wma
  • avconv -f alsa -i pulse -ar 44100 -ab 128k -acodec wmav2 audio3.wma

WMA formatında -ac 1 (mono) ataması “output buffer size is too small” şeklinde hata verdi.

Record audio from system sound, not only from microphone:

  • avconv -f alsa -i pulse -ar 44100 -ab 64k -ac 1 -acodec libvorbis audio.ogg

During recording, open volume control (pavucontrol) and goto Recording tab. You’ll see ffmpeg / avconv listed there.

Change audio capture from “Built-in Audio Analog Stereo” to “Monitor of Built-in Audio Analog Stereo“.

Now it should record system and application audio instead of microphone.

If no signal, goto Input Devices tab and unmute “Monitor of Built-in Audio Analog Stereo”


Kullanılabilir aygıtlar...

  • arecord -L

ile listelenen aygıtların bir kısmı kullanılabilmektedir.

Aşağıdaki kullanımlarda mikrofondan kayıt yapılmaktadır.

  • ffmpeg -f alsa -i plughw:0,0 rec.mp3
  • ffmpeg -f alsa -i front:0,0 rec.mp3
  • ffmpeg -f alsa -i hw:0,0 rec.mp3
  • ffmpeg -f alsa -i surround40 rec.mp3
  • ffmpeg -f alsa -i surround71:0,0 rec.mp3

Aşağıdaki kullanımda sistem sesi kaydedilmektedir.

  • ffmpeg -f alsa -i default rec.mp3
  • ffmpeg -f alsa -i pulse rec.mp3

jack çalışıyorsa, aşağıdaki kullanımda yeni bir kanal tanımlanabilmekte ve sonrasında istenen kanallar bu yeni kanala yönlendirilerek kaydedilebilmektedir.

  • ffmpeg -f jack -i rec1 rec.mp3

jack

Sistem sesi ve mikrofon sesini aynı anda kaydedebilmek için jack adlı gelişmiş bir uygulamanın işe yaradığı ifade edilmektedir.

https://help.ubuntu.com/community/HowToJACKConfiguration

http://ubuntuforums.org/showthread.php?t=806730

http://ubuntuforums.org/showthread.php?t=1707671

sudo apt-get install jackd qjackctl

Sanal ses kartı oluşturma:

http://ubuntuforums.org/showthread.php?t=914405

Redirect Pulse to Jack

  • sudo apt-get install pulseaudio-module-jack
  • pactl load-module module-jack-sink channels=2; pactl load-module module-jack-source channels=2; pacmd set-default-sink jack_out

Terminalde yukarıdaki komut çalıştırıldığında, QJackCtl içerisinde iki yeni kanal oluşmaktadır. Böylece yönlendirme yapılarak, hem mikrofon hem de sistem sesi kaydedilebilmektedir.

https://github.com/jackaudio/jackaudio.github.com/wiki/WalkThrough_User_PulseOnJack

Veya otomatik başlatmak için QJackCtl > Setup > Options penceresinde bulunan

Execute script after startup kutusu aktifleştirilir ve şu komut yazılır:

  • pacmd load-module module-jack-source channels=2; pacmd load-module module-jack-sink channels=2;

http://puredata.info/docs/JackRoutingMultichannelAndBrowserAudio/




Merge Audio and Video with ffmpeg

Ses ve müzik birleştirme...

  • avconv -i audio.mp3 -i screen.mp4 -acodec copy -vcodec copy merged.mp4

Video kısa olduğunda müzik sürüyor...

Şayet uzunluk kısa olan dosyaya göre olacaksa -shortest parametresi kullanılabilir.

  • avconv -i audio.mp3 -i video2.mp4 -shortest -c copy joint.mp4
  • ffmpeg -i capture_2.webm -i editorlere_ozel_2.ogg -map 0:0 -map 1:0 -c copy -shortest screencast_2.webm



Şayet video da ses barındırıyorsa, o zaman -map ile hangi dosyadan hangi akışın (stream) alınacağı belirtilebilir. -map 1:0 ifadesi, ikinci -i ile belirtilen dosyanın ilk akışını alır.

Aşağıdaki örnekte, 1. dosyanın 2. akışı ile 2. dosyanın 1. akışı birleştirilmektedir. Yani birinin videosu, diğerinin sesi.

  • avconv -i video1.mp4 -i video2.mp4 -map 0:1 -map 1:0 -acodec copy -vcodec copy joint.mp4

Bir yada birkaç dosyadaki stream bilgilerini öğrenmek için

  • ffmpeg -i video.mp4 -i video2.mp4



İki videonun görüntülerini birleştirmek birbirine eklemek!!!!

  • avconv -i video2.mp4 -i video3.mp4 -map 0:0 -map 1:0 -vcodec copy joint.mp4
  • avconv -i desk1.webm -i desk2.webm -map 0:0 -map 1:0 -vcodec copy joint.webm



Birleştirme sonrası oluşan video vlc ile açıldığında 2 ayrı pencerede eşzamanlı olarak oynatılmaya başlandı. Video sona eklenmedi yani. Ek bir stream olarak eklendi.

-map 0 gibi bir ifade ile, ilk dosyanın tüm akışları (stream) alınır. Aşağıdaki örnekte, 1. dosyanın görüntü kısmı alınırken, ikinci videonun hem ses hem görüntü kısmı alınmaktadır.

  • avconv -i video1.mp4 -i video2.mp4 -map 1:0 -map 0 -acodec copy -vcodec copy joint.mp4

Sonuç dosya açıldığında, haliyle iki görüntü birden oynatılmakta ve bir ses çalmaktadır.

O halde, iki adet müziği bir videoda toplayabilmeli ve aynı anda çaldırabilmeliyiz... Deneyelim...

  • avconv -i audio2.mp3 -i video1.mp4 -map 0:0 -map 1 -acodec copy -vcodec copy joint.mp4

Evet! Her ne kadar VLC player sesleri aynı anda oynatmasa da stream olarak iki ayrı ses eklendi videoya.

Ayrıca ilk yazılan -map ifadesindeki ses varsayılan olarak çaldı. -map parametreleri yer değiştirildiğinde diğer ses varsayılan olarak çalmaya başladı.

Bu duruma göre, iki ayrı ses dosyası yeni bir ses dosyası olarak birleştirildiğinde, sonuç dosyada 2 ayrı stream barınsa da bir tanesinın varsayılan olarak oynatılması beklenir.

avconv -i audio.mp3 -i audio2.mp3 -map 1 -map 0:0 -acodec copy out.mp4

  • avconv -i audio.mp3 -i audio2.mp3 -map 1 -map 0:0 -acodec copy out.mp3

Sanırım mp3 biçimi çok sayıda stream desteklemiyor ki, sonuç dosya bozuk olarak çaldı.

Ancak mp4 olarak çıktı alındığında görüntü barındırmayan 2 ayrı ses stream birleşmiş oldu.

  • avconv -i audio.mp3 -i audio2.mp3 -map 1 -map 0:0 -acodec copy out.mp4

Ses dosyasının bir kısmını alarak birleştirme yapmak:

ffmpeg -ss 0:02:42 -i hm1.ogg -t 0:06:11 -i gc_2013-02-09_1.webm -map 0:0 -map 1:0 -acodec copy -vcodec copy gc_joint.webm




------

To select all video and the third audio stream from an input file:

ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT

To map all the streams except the second audio, use negative mappings

ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT

For creating a video from many images:

ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi

From http://ffmpeg.org/ffmpeg.html#Advanced-options

  • avconv -f image2 -r 1/5 -i export_wink%d.png out.webm
  • avconv -f image2 -r 1/5 -i export_wink%d.png -vframes 1500 out.wmv

Single image…

  • ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4

And with direct copy mp3 audio file..

  • ffmpeg -loop 1 -i img001.png -i test.mp3 -c:v libx264 -c:a copy -t 60 -pix_fmt yuv420p out.mp4
  • ffmpeg -f concat -i <(for c in {0..11111}; do echo "file /home/m1/sil/ssback.png"; echo "duration 0.5"; done) -i test.mp3 -c:a copy -map 0:v -map 1:a -vf "subtitles=test.srt" -shortest test.avi.mkv




Alternatif olarak concat ile her bir resim süresini belirlemek de mümkün.

Öncelikle aşağıdaki gibi bir içeriğe sahip bir metin dosyası oluşturulur. list.txt

--------------

ffconcat version 1.0

file img001.png

duration 3.5

file img002.png

duration 5.7

file img003.png

duration 4.4

file img004.png

duration 3

------------------

Ardından şu şekilde video oluşturulur.

  • ffmpeg -i list.txt out.avi
  • ffmpeg -f concat -i list.txt -i test.mp3 -pix_fmt yuv420p -r 25 -c:a copy out.avi
  • ffmpeg -f concat -i list.txt -i test.mp3 -r 15 -shortest out.mp4
  • ffmpeg -f concat -i list.txt -i test.mp3 -acodec copy -vcodec libx264 -r 15 -shortest out.mp4
  • ffmpeg -f concat -i list.txt -i test.mp3 -acodec copy -r 15 - s 640x480 -aspect 16:9 -shortest out.mp4

Not:

  • İlk başlarda birkaç saniyelik kısa aralıklarla 3-5 adet resim eklenince ötesi sorun olmuyor. Aksi halde, video ilk saniyelerde kırpılıyor.
  • ffmpeg 'in bazı son sürümlerinde (2014-11) çalışmamaktadır. Muhtemelen derleme parametreleriyle ilgilidir. Çalıştığı bazı versiyonlar:
    ffmpeg Jul 16 2014 (64 bit) - Oct 31 2014 (32 bit)



Fix Audio/Video

Dosya uzunluğu hatalı ve ileri geri alınamıyorsa, ffmpeg ile düzeltme yapılabilir.

  • ffmpeg -i 2013-03-31_20.webm -map 0:a -map 0:v -c copy 2013-03-31_20_fix.webm

Delaying the audio or the video

Remember to put the source that needs delaying after the "-itsoffset" option.

itsoffset negatif değer alabilmektedir.

Aşağıdaki örnekte sonuçta, sesin 1. dakikadan itibaren başladığı bir video elde edilmiş olunuyor.

  • ffmpeg -itsoffset -0:01:00 -i video.avi -i audio.ogg -map 0:v -map 1:a -c copy "result.mkv"

Aşağıdaki iki örnek aynı sonucu vermekte ve sesii birkaç saniye öne almak veya videoyu ötelemektedir.

  • ffmpeg -i 2013-03-31_20.webm -itsoffset 0:00:32.200 -i 2013-03-31_20.webm -map 0:a -map 1:v -c copy 2013-03-31_20_delay.webm
  • ffmpeg -i 2013-03-31_20.webm -itsoffset -0:00:32.200 -i 2013-03-31_20.webm -map 0:v -map 1:a -c copy 2013-03-31_20_delay.webm

Ek olarak, farklı ses ve video dosyaları birleştirilirken de sesin belli bir noktadan başlaması sağlanabilir.

Öteleme sırasında dosyadan kesit de alınabilmektedir.

  • ffmpeg -i 2013-03-31_20.webm -itsoffset 0:00:32.200 -i 2013-03-31_20.webm -map 0:a -ss 0:20:00 -map 1:v -c copy 2013-03-31_20_cut.webm

Anlaşılan -ss ifadesi -map ifadesiyle etkileşebiliyor



---------

http://stackoverflow.com/questions/10116430/ffmpeg-stream-offset-command-itsoffset-not-working

Delay 1 second in first input video and the second input audio just make a copy

  • ffmpeg -itsoffset 00:00:01.000 -i "d:\Video1.mp4" -i "d:\Video1.mp4"

-map 0:v -map 1:a -vcodec copy -acodec copy -f mp4 -threads 2 -v warning "Video2.mp4"

Delay 1 second in second input audio and the first input video just make a copy

  • ffmpeg -y -i "d:\Video1.mp4" -itsoffset 00:00:01.000 -i "d:\Video1.mp4"

-map 0:v -map 1:a -vcodec copy -acodec copy

-f mp4 -threads 2 -v warning "Video2.mp4"



Video formatlarıyla ilgili uygun birkaç eşleştirme... (Format ile Codec uyumu)

h264 + mp3 : mp4

h264 + aac : mp4

vpx + ogg : webm

mkv + mp3 : mkv

ogv + ogg : ogg

wmv + wma : wmv



Aynı biçimli videoları art arda ekleyerek birleştirmek. (ffmpeg v1.1+)

How to Concatenate Media Files

  • ffmpeg -f concat -i <(echo file '/media/os/sil/cdn/test4-part1.mpg' ; echo file '/media/os/sil/cdn/test4-part2.mpg' ) -c:a copy -c:v copy joint3.mpg
  • ffmpeg -f concat -i <(for f in test4-part*.mpg; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy joint.mpg
  • ffmpeg -f concat -i <(printf "file '$PWD/%s'\n" rec1.3gpp silence.m4a rec.m4a) -c copy joint.m4a



Harici Liste Yöntemi:

Dosya listesi oluşturulur. Örnek: list.txt

#comment line

file ‘vid_1.webm’

file ‘vid_2.webm’

file ‘vid_3.webm’

Ardından şu komutla birleştirme yapılabilir.

  • ffmpeg -f concat -i list.txt -c copy out.webm

list.txt uygun biçimde hazırlanıp aşağıdaki denemeler yapıldığında sonuç başarılı oldu.

  • ffmpeg -f concat -i list.txt -c copy concat.mp3
  • ffmpeg -f concat -i list.txt -c copy concat.flv
  • ffmpeg -f concat -i concat.txt -c copy cap.mp4
  • ffmpeg -f concat -i concat.txt -c copy out.wav
  • ffmpeg -f concat -i concat.txt -c copy joint.wma
  • ffmpeg -f concat -i concat.txt -c copy joint.wmv



Yapılan denemede tüm parametreleri aynı; fakat birinin -r 25, diğerinin -r 30 olan iki (webm formatlı) videonun birleşimi de başarılı oldu.

Tek satırda aşağıdaki gibi birleştirme yapılabildiği ifade edilse de yapılan denemelerde sonuç başarısız oldu.

ffmpeg -i "concat:audio.mp3|audio.mp3|audio.mp3" -c copy output.mp3

ffmpeg v1.2.6+ ile şu komut başarılı oldu:

  • ffmpeg -i "concat:vid1.avi|vid2.avi" -c copy joint.avi
  • ffmpeg -i "concat:test4-part1.mpg|test4-part2.mpg|test4-part3.mpg" -c copy output.mpg



Ancak şu komut başarısız oldu:

  • ffmpeg -i "concat:p1.webm|p2.webm" -c copy joint.webm

Ancak harici liste ile sonuca varılabildi:

  • ffmpeg -f concat -i c.txt -c copy joint.webm





MULTIPLE OUTPUT

ffmpeg ile birden fazla sayıda ve formatta çıktı alınabilmektedir.

  • ffmpeg -f alsa -i pulse -acodec libvorbis -ar 44100 -ab 64k -ac 1 out1.ogg out2.ogg
  • ffmpeg -f alsa -i pulse -acodec libvorbis -ar 44100 -ab 64k -ac 1 out1.ogg -acodec libmp3lame -ac 1 -ar 44100 -ab 64k out2.mp3

Bu şekilde, yayını hem yerel dosyaya kaydetmek hem de sunucuya göndermek mümkün:

  • ffmpeg -f jack -i rec -f video4linux2 -i /dev/video0 -b:v 1000k -r 10 -s 640x480 -acodec libvorbis -ar 44100 -ab 64k -ac 1 rec.webm http://lnx.4yon.org:8080/webm.ffm

Yayını yerelde yüksek kalitede tutup sunucuya düşük kalitede göndermek de mümkün.

  • ffmpeg -f alsa -i pulse -f video4linux2 -i /dev/video0 -b:v 100k -r 15 -s 640x480 -acodec libvorbis -ar 44100 -ab 64k -ac 1 http://lnx.4yon.org:8080/webm.ffm -b:v 1000k -r 20 -ar 44100 -ab 64k -ac 1 rec.webm



Rotate video with ffmpeg filters
  • ffmpeg -i VID_20130711_134414.mp4 -vf vflip out.webm # alt-üst
  • ffmpeg -i VID_20130711_134414.mp4 -vf vflip,hflip out.webm # alt-üst ve sol-sağ
  • ffmpeg -i VID_20130711_134414.mp4 -vf "transpose=1" out.webm # 90 derece döndür

transpose parameters:

0: 90CounterCLockwise and Vertical Flip, 1: 90Clockwise, 2: 90CounterClockwise, 3: 90Clockwise and Vertical Flip

Kullanılabilir filtreler için: ffmpeg -filters

Anlaşıldığı kadarıyla, verinin işlenmesi gerekiyor. -c copy kullanıldığında sonuçta bir etki olmamıştı.

Veri işlenmesine gerek kalmadan, videoyu döndürerek oynatmak da mümkün:

  • ffplay input.mp4 -vf hflip,vflip



Stream with ffmpeg

https://trac.ffmpeg.org/wiki/StreamingGuide

Stream Microphone (audio only)

  • ffmpeg -f alsa -i pulse -c:a libmp3lame -f mulaw -f rtp rtp://127.0.0.1:1234

To open the stream:

  • ffplay rtp://127.0.0.1:1234
  • ffplay udp://127.0.0.1:1234
  • vlc rtp://127.0.0.1:1234



Stream to UDP protocol

192.168.1.35 is the phone (Android) which is in the same network of the pc where the commands run.

ffmpeg -f alsa -i pulse -c:a libmp3lame -f mpegts udp://192.168.1.35:1234

Sending a UDP stream directly to the client. On the client the stream can be listened in a player like VLC by typing the following network URL:

udp://@:5000

Live Screencast with ffmpeg

http://blog.devinrkennedy.com/2009/10/live-screencasting-using-ffmpeg.html

Setup a configuration file. For example: ffserver.conf

Start server:

  • ffserver -f ffserver.conf

Capture audio/video

  • ffmpeg -f alsa -i pulse -f x11grab -s 320x240 -i :0.0 http://localhost:8080/feed1.ffm
  • avconv -f alsa -i pulse -f x11grab -s 320x240 -i :0.0 -acodec libmp3lame -ac 1 -ar 44100 -ab 64k http://localhost:8080/feed1.ffm
  • avconv -f alsa -i pulse -f x11grab -s 320x240 -i :0.0 -acodec libmp3lame -ac 1 -ar 44100 -ab 64k -r 5 -b 1M -vcodec libvpx http://localhost:8080/feed1.ffm
  • ffmpeg -f alsa -i pulse -f video4linux2 -i /dev/video0 http://localhost:8080/webm.ffm -vcodec libvpx -vb 500k -r 20 -acodec libvorbis -ac 1 -ar 44100 -ab 32k `date +%Y-%m-%d_%H-%M.webm`




For audio only broadcast:

  • avconv -f alsa -i pulse -ar 44100 -ab 64k -ac 1 -acodec libmp3lame http://localhost:8080/feed1.ffm

Connect to the server to get broadcasting with a client like VLC, using http://localhost:8080/live.asf

By configuring firewall and port forwarding you broadcast to the internet. Remote user can access to the server by http://IP:Port/stream_name.

Example: http://local.mbirgin.com:8080/live.mp3

For more: http://ffmpeg.org/sample.html

http://ffmpeg.org/trac/ffmpeg/wiki/Streaming%20media%20with%20ffserver (including ogg streaming config)

ffserver.conf file sample below (mp3, audio only)

------------------------------------------------------

Port 8080

BindAddress 0.0.0.0

MaxHTTPConnections 2000

MaxClients 1000

MaxBandwidth 1000

CustomLog -

#NoDaemon

<Feed feed1.ffm>

File /tmp/feed1.ffm

FileMaxSize 200K

# ACL allow 127.0.0.1 #sadece local kaynak kabul et.

</Feed>



# MP3 audio

<Stream live.mp3>

Feed feed1.ffm

Format mp3 #mp2

AudioCodec libmp3lame

AudioBitRate 64

AudioChannels 1

AudioSampleRate 44100

NoVideo

</Stream>

-------------------------------------------------

Linux sunucuda (lnx.4yon.org) ffserver çalıştırılılıp, ffmpeg ile yerel bilgisayardan yayın gönderilerek dağıtımı yapılabildi!

Sunucuda (lnx.4yon.org):

  • ffserver -f /var/www/ffserver.conf

Yerelde:

  • ffmpeg -i ‘test.mp3’ http://lnx.4yon.org:8080/feed1.ffm

Eş zamanlı gönderim için -re parametresi eklenebilir.

Ve yayın, VLC player ile dinlenilebildi:

  • http://lnx.4yon.org:8080/live.mp3

Windows XP ile yayın gönderimi de başarılı oldu.

Sunucuda ffmpeg ile bir başka radyo kanalından yayın alınıp dağıtımı yapılabildi.

Aşağıdaki komutlar sunucuda çalıştırılarak sonuç alındı.

  • ffserver -f /var/www/ffserver.conf
  • ffmpeg -i http://mediaserver3.akradyo.net/shoutcast/akra.stream/playlist.m3u8 -acodec copy http://localhost:8080/feed1.ffm






ffmpeg Sorun Giderme

Hata: error while loading shared libraries: libfaac.so.0: cannot open shared object file:

Çözüm:

sudo find / -name libfaad.so*

sudo ln -s /usr/lib/libfaad.so /usr/lib/libfaac.so.0

Hata: ffmpeg: error while loading shared libraries: libx264.so.129: cannot open shared object file: No such file or directory

Çözüm: find / -name libx264.so*

sudo ln -s /usr/lib/x86_64-linux-gnu/libx264.so /usr/lib/x86_64-linux-gnu/libx264.so.129

Bulunamayan kütüphaneler, aşağıdaki komutla bulundukları kütüphaneler tespit edilerek kurulabilirler.

Örnek:

apt-cache search libass

sudo apt-get install libass-dev

----

MP4 - libx264 Note for Web Video:

You can add -movflags +faststart as an output option if your videos are going to be viewed in a browser. This will move some information to the beginning of your file and allow the video to begin playing before it is completely downloaded by the viewer.

https://trac.ffmpeg.org/wiki/Encode/H.264






Merge Videos / Audios

We can use mkvmerge to achieve this. Package name: mkvtoolnix

This program allows you to concatenate mkv files with identically-encoded streams to a single file. Example:

  • mkvmerge -o complete.mkv part1.mkv +part2.mkv +part3.mkv +part4.mkv

All the parts must have exactly the same size/framerate/encoding parameters, otherwise it won’t work. You can’t add files with different encoding options to each other.

  • mkvmerge -o out.ogg audio.ogg +audio1.ogg +audio2.ogg +audio3.ogg
  • mkvmerge -o cap.webm cap_1.webm +cap_2.webm +cap_3.webm
  • mkvmerge -o cap.mp4 cap1.mp4 +cap2.mp4 +cap3.mp4



wma fomatı desteklenmemektedir. “… non-supported file type (Windows Media (ASF/WMV)).”


m1gin 0

https://www.youtube.com/watch?v=hElDsyuAQDA

Join / Merge media files:

  • ffmpeg -i vid1.avi -i vid2.avi -filter_complex "[0][1]concat" out.avi
  • ffmpeg -i vid1.avi -i vid2.avi -i vid3.avi -i vid4.avi -filter_complex "[0][1][2][3]concat=n=3" out.avi


  • ffmpeg -i MVI_4860.MOV -i bg.jpeg -filter_complex "[0]colorkey=color=#00FF00:similarity=0.1[keyed];[1][keyed]overlay" -t 10 out.avi

Timeline Editing

Enable filter for specific position:​​​​​​​

  • ffmpeg -i MVI_4860.MOV -filter_complex "[0]smartblur=lr=5:enable='between(t,5,10)'" -t 10 out.avi

t: timestamp seconds
n: current frame number
w, h: width and height of input video

gt(x,y), gte(x,y), lt(x,y), lte(x,y):

comparision functions

between(x, min, max)

returns 1 if x is between or equal to min and max

if(x,y,z), ifnot(x,y,z)

Tests x against 0, returns y if true, z if not

Transition

ffmpeg -i vid1.avi -i vid2.avi -q 6 -filter_complex "[0][1]blend=all_expr='A*(if(gte(T,4),1,T/4))+B*(1-(if(gte(T,4),1,T/4)))'" out.avi


Add to: