Difference between revisions of "VideoEncodingTips"

From TAMI
Jump to navigationJump to search
 
(31 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= MTS to webm =
+
=encoding=
 +
[http://www.rodrigopolo.com/ffmpeg/ ffmpeg script generator]
  
 +
== MTS to webm ==
 
Used ffmpeg to concatenate the files without reencoding (codec copy):
 
Used ffmpeg to concatenate the files without reencoding (codec copy):
 
  ffmpeg -f concat -i files -c copy whole.mts
 
  ffmpeg -f concat -i files -c copy whole.mts
Line 19: Line 21:
 
  ffmpeg -i whole.webm -ss 00:12:55 -to 20:07 -codec copy 03_EWB_Oren.webm
 
  ffmpeg -i whole.webm -ss 00:12:55 -to 20:07 -codec copy 03_EWB_Oren.webm
  
= cropping with ffmpeg =
+
== cropping with ffmpeg ==
ffmpeg -i atlassian_jira_workflow_graph_view_guides_demonstration_20150305_orig.webm -vf "crop=1920:1200:0:0" test.webm
+
ffmpeg -i atlassian_jira_workflow_graph_view_guides_demonstration_20150305_orig.webm -vf "crop=1920:1200:0:0" test.webm
 +
 
 +
== cropping with gstreamer ==
 +
gst-launch-0.10 -v filesrc location=./atlassian_jira_workflow_graph_view_guides_demonstration_20150305_orig.webm ! decodebin ! ffmpegcolorspace ! videocrop top=0 left=0 right=1920 bottom=0 ! vp8enc ! webmmux ! filesink location=whole.webm
 +
 
 +
== video contact sheet (thumbnail) creation==
 +
from (forum.videohelp)[http://forum.videohelp.com/threads/304375-Best-Batch-Processing-Video-Contact-Sheet-Creator-software]
 +
 
 +
ffmpeg -i %1 -vf select='gt(scene\,0.5)',scale=192:108,tile -frames:v 1 %1_preview_scene.png
 +
 
 +
ffmpeg -i %1 -f GIF -vf "fps=fps=5,scale=out_range=auto:force_original_aspect_ratio=decrease:'if(gt(a,1/1),128,-1)
 +
':'if(gt(a,1/1),-1,128)':sws_dither=a_dither:sws_flags=bicubic+accurate_rnd+full_chroma_inp+full_chroma_int:
 +
sws_dither=a_dither,pad=128:128:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -pix_fmt rgb8 -loop 0 -final_delay 1 - 
 +
default_delay 1 -y %1_thumb.gif
 +
 
 +
ffmpeg -i %1 -vf select='eq(pict_type\,I)',scale=192:108,tile -frames:v 1 %1_preview_I_frame.png
 +
 
 +
=Streaming=
 +
[http://en.wikipedia.org/wiki/Streaming_media Streaming_media on wikipedia]
 +
 
 +
==icecast2/ogg==
 +
[http://icecast.org/ Icecast2] is a streaming media server
 +
offical [http://www.icecast.org/docs/icecast-trunk/ docs]
 +
 
 +
===how to===
 +
 
 +
====broadcast server====
 +
first install icecast server , only done once and on the server.<Br>
 +
in my case its an arch linux server
 +
  ## to configure
 +
  # sudo vim /etc/icecast.xml
 +
  ## to manage service
 +
  # systemctl enable/stop/restart icecast
 +
 
 +
====broadcast client====
 +
[http://icecast.org/ezstream/ ezstream] is what we use, it can be told to re encode, use playlists ,shuffle, load custom metadata per file etc. <br>
 +
runs on linux and windows. <br>
 +
 
 +
1. prepare a playlist.m3u file, see 'man ezstream' for more. <br>
 +
could be a easy as getting to your media folder and
 +
ls > playlist.m3u
 +
2. then run
 +
ezstream -c ezstream_reencode_theora.xml
 +
 
 +
find an example xml configuration file at /usr/share/examples/ezstream/
 +
 
 +
this will show on http://yair.cc:8000/sff.ogg<br>
 +
you can then see stats on http://yair.cc:8000/ <br>
 +
 
 +
you might want to start with ffmpeg2theora|oggfwd for testing (see below)
 +
 
 +
done
 +
 
 +
====alternatives and addons====
 +
oggfwd is basicly a cat, so very light. if you already have an ogg/theora encoded file and just want to stream a file then here is an example of '''quick streaming to server'''
 +
# this example will show at tami.org.il:8000/channel
 +
# cat zimmertlv-92244715-streamReady.ogv | oggfwd  tami.org.il 8000 password /channel
 +
 
 +
ffmpeg2theora is harder on the server. as it re-encodes to ogg/theora <br>
 +
so better encode beforehand. example of video encoding '''from mp4 to ogg''' (ogv)
 +
# ffmpeg -i input.mp4 -codec:v libtheora -qscale:v 5 -codec:a libvorbis -qscale:a 4 output.ogv
 +
 
 +
example of '''on the fly re-encoding using ffmpeg2theora and then streaming using oggfw'''
 +
this is the easiest way to stream, but you need an ok pc for that as you re-encode the video.
 +
# -p preview is 288Kbps video
 +
# -v 4 = 500Kbps
 +
ffmpeg2theora --no-skeleton -p preview video_source.mp4 -o /dev/stdout | oggfwd tami.org.il 8000 password /mount_name
 +
 
 +
====alt methods====
 +
tested audio streaming using [http://butt.sourceforge.net/ BUTT] on windows<br>
 +
tested audio streaming using [http://novastreamapps.blogspot.fr/ BroadcastMySelf] for android<br>
 +
 
 +
tested video streaming using ffmpeg2theora | oggfwd on arch<br>
 +
tested video streaming using [http://icecast.org/ezstream/ ezstream] on arch<br>
 +
 
 +
==nginx==
 +
'''in research'''
 +
windows is so easy on this one :>  [https://github.com/illuspas/nginx-rtmp-win32 beanies]<br>
 +
needed for [ttps://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/ OBS streaming ]
 +
 
 +
 
 +
built following instructions on arch
 +
* [https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp Getting-started-with-nginx-rtmp]
 +
 
 +
rtmp:// works , html is lacking documentation
 +
 
 +
concat video files example
 +
for i in {1..4}; do printf "file '%s'\n" input.mp4 >> list.txt; done
 +
ffmpeg -re -f concat -i list.txt -c copy -f flv rtmp://localhost/myapp/mystream
 +
 
 +
[http://video.stackexchange.com/questions/12905/repeat-loop-input-video-with-ffmpeg?newreg=8f9956f2e8aa4f0189555ba019cfa77c via]
 +
 
 +
==FFserver==
 +
'''not using currently'''
 +
documentation is a mess
 +
 
 +
could it be, the guide to rule them all, so much updated !<br>
 +
Streaming Tutorial II: '''http://www.willus.com/author/streaming2.shtml'''
 +
 
 +
===how to===
 +
h264 to ogg is [https://trac.ffmpeg.org/ticket/3418 broken] , might be more 
 +
*[https://www.ffmpeg.org/ffserver-all.html man, is this updated?]
 +
*[http://trac.ffmpeg.org/wiki/Streaming%20media%20with%20ffserver offical guide]
 +
*[https://www.virag.si/2012/11/streaming-live-webm-video-with-ffmpeg/ Streaming Live WebM Video With FFmpeg.]
 +
*[http://www.vitki.net/book/page/2-streaming-vlc-ffserver guide for windows client and linux server]
 +
 
 +
a [https://github.com/sdrsdr/HLS-Segmenter segmentator] (might be) needed for apple support
 +
 
 +
video tag works with [http://mediaelementjs.com/ mediaelementjs.js]
 +
 
 +
=more=
 +
 
 +
=== inspiration ===
 +
*[http://radio.7chan.org:8000/CH7 channel7] runs an icecast2 server which ... stream ogg theora vorbis encoded videos to, using a program called ezstream
 +
*[http://x264dev.multimedia.cx/archives/249 x264: the best low-latency video streaming platform in the world]
 +
 
 +
*[http://www.rudiswiki.de/wiki9/AndroidFPView instrcutions to build your telepercnse gimp]
 +
 
 +
 
 +
===alternatives and addons ===
 +
 
 +
*[https://bbs.archlinux.org/viewtopic.php?id=178617 mplayer tips on using without X]
 +
*[http://www.mltframework.org MLT] Author, manage, and run multitrack audio/video compositions
 +
* [https://obsproject.com/ Open Broadcaster Software]  open source software for live streaming and recording
 +
* [https://obsproject.com/forum/threads/private-rtmp-server-preconfigured-virtualbox-image.5873/ Private RTMP server] preconfigured obs virtualbox image
 +
*[https://wiki.xiph.org/GST_cookbook gstreamer examples] for streaming, but where is the vp8 to icecast :/
 +
* the holy grail, vp8+gstreamer+icecast
 +
* [http://icecast.org/ezstream/ Ezstream] is a command line source client for Icecast media streaming servers.
 +
* ffmpeg2theora- [http://v2v.cc/~j/ffmpeg2theora/examples.html examples] and [http://v2v.cc/~j/oggfwd/ small helper]
 +
* Streaming howto for [http://en.flossmanuals.net/FFmpeg2Theora/StreamingDV/ linux] and [http://www.youtube.com/watch?v=LJNyJMcjgy8 windows]

Latest revision as of 15:38, 7 January 2018

encoding

ffmpeg script generator

MTS to webm

Used ffmpeg to concatenate the files without reencoding (codec copy):

ffmpeg -f concat -i files -c copy whole.mts

where files contains:

file 00001.MTS
file 00002.MTS

etc.

Used gstreamer to convert to webm. This was after failed (i.e. success but garbage output - small random squares) attempts with both mencoder and ffmpeg:

gst-launch-0.10 filesrc location=whole.mts ! decodebin name=demux ! queue ! ffmpegcolorspace ! vp8enc ! webmmux name=mux ! filesink location=whole.webm demux. ! queue ! progressreport ! audioconvert ! audioresample ! vorbisenc ! mux.

Then used ffmpeg to cut without copy, this is almost instantaneous on a SSD drive (whole.webm is 914M):

ffmpeg -i whole.webm -ss 00:12:55 -to 20:07 -codec copy 03_EWB_Oren.webm

cropping with ffmpeg

ffmpeg -i atlassian_jira_workflow_graph_view_guides_demonstration_20150305_orig.webm -vf "crop=1920:1200:0:0" test.webm

cropping with gstreamer

gst-launch-0.10 -v filesrc location=./atlassian_jira_workflow_graph_view_guides_demonstration_20150305_orig.webm ! decodebin ! ffmpegcolorspace ! videocrop top=0 left=0 right=1920 bottom=0 ! vp8enc ! webmmux ! filesink location=whole.webm

video contact sheet (thumbnail) creation

from (forum.videohelp)[1]

ffmpeg -i %1 -vf select='gt(scene\,0.5)',scale=192:108,tile -frames:v 1 %1_preview_scene.png
ffmpeg -i %1 -f GIF -vf "fps=fps=5,scale=out_range=auto:force_original_aspect_ratio=decrease:'if(gt(a,1/1),128,-1)
':'if(gt(a,1/1),-1,128)':sws_dither=a_dither:sws_flags=bicubic+accurate_rnd+full_chroma_inp+full_chroma_int: 
sws_dither=a_dither,pad=128:128:(ow-iw)/2:(oh-ih)/2,setsar=sar=1/1" -pix_fmt rgb8 -loop 0 -final_delay 1 -  
default_delay 1 -y %1_thumb.gif 
ffmpeg -i %1 -vf select='eq(pict_type\,I)',scale=192:108,tile -frames:v 1 %1_preview_I_frame.png

Streaming

Streaming_media on wikipedia

icecast2/ogg

Icecast2 is a streaming media server offical docs

how to

broadcast server

first install icecast server , only done once and on the server.
in my case its an arch linux server

 ## to configure
 # sudo vim /etc/icecast.xml
 ## to manage service
 # systemctl enable/stop/restart icecast

broadcast client

ezstream is what we use, it can be told to re encode, use playlists ,shuffle, load custom metadata per file etc.
runs on linux and windows.

1. prepare a playlist.m3u file, see 'man ezstream' for more.
could be a easy as getting to your media folder and

ls > playlist.m3u

2. then run

ezstream -c ezstream_reencode_theora.xml 

find an example xml configuration file at /usr/share/examples/ezstream/

this will show on http://yair.cc:8000/sff.ogg
you can then see stats on http://yair.cc:8000/

you might want to start with ffmpeg2theora|oggfwd for testing (see below)

done

alternatives and addons

oggfwd is basicly a cat, so very light. if you already have an ogg/theora encoded file and just want to stream a file then here is an example of quick streaming to server

# this example will show at tami.org.il:8000/channel
# cat zimmertlv-92244715-streamReady.ogv | oggfwd  tami.org.il 8000 password /channel

ffmpeg2theora is harder on the server. as it re-encodes to ogg/theora
so better encode beforehand. example of video encoding from mp4 to ogg (ogv)

# ffmpeg -i input.mp4 -codec:v libtheora -qscale:v 5 -codec:a libvorbis -qscale:a 4 output.ogv

example of on the fly re-encoding using ffmpeg2theora and then streaming using oggfw this is the easiest way to stream, but you need an ok pc for that as you re-encode the video.

# -p preview is 288Kbps video
# -v 4 = 500Kbps
ffmpeg2theora --no-skeleton -p preview video_source.mp4 -o /dev/stdout | oggfwd tami.org.il 8000 password /mount_name

alt methods

tested audio streaming using BUTT on windows
tested audio streaming using BroadcastMySelf for android

tested video streaming using ffmpeg2theora | oggfwd on arch
tested video streaming using ezstream on arch

nginx

in research windows is so easy on this one :> beanies
needed for [ttps://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/ OBS streaming ]


built following instructions on arch

rtmp:// works , html is lacking documentation

concat video files example

for i in {1..4}; do printf "file '%s'\n" input.mp4 >> list.txt; done
ffmpeg -re -f concat -i list.txt -c copy -f flv rtmp://localhost/myapp/mystream

via

FFserver

not using currently documentation is a mess

could it be, the guide to rule them all, so much updated !
Streaming Tutorial II: http://www.willus.com/author/streaming2.shtml

how to

h264 to ogg is broken , might be more

a segmentator (might be) needed for apple support

video tag works with mediaelementjs.js

more

inspiration


alternatives and addons