Tumgik
andrewjsinclair · 11 years
Text
Useful script for multi-rate HLS output from ffmpeg
#!/bin/bash VIDSOURCE="$1" RESOLUTION="854x480" BITRATE1="800000" BITRATE2="600000" BITRATE3="400000" AUDIO_OPTS="-c:a libfaac -b:a 160000 -ac 2" VIDEO_OPTS1="-s $RESOLUTION -c:v libx264 -b:v $BITRATE1 -vprofile
baseline -preset medium -x264opts level=41"
VIDEO_OPTS2="-s $RESOLUTION -c:v libx264 -b:v $BITRATE2 -vprofile
baseline -preset medium -x264opts level=41"
VIDEO_OPTS3="-s $RESOLUTION -c:v libx264 -b:v $BITRATE3 -vprofile
baseline -preset medium -x264opts level=41"
OUTPUT_HLS="-hls_time 3 -hls_list_size 10 -hls_wrap 30 -start_number 1" ffmpeg -i "$VIDSOURCE" -y -threads 4 \        $AUDIO_OPTS $VIDEO_OPTS1 $OUTPUT_HLS stream_hi.m3u8 \        $AUDIO_OPTS $VIDEO_OPTS2 $OUTPUT_HLS stream_med.m3u8 \        $AUDIO_OPTS $VIDEO_OPTS3 $OUTPUT_HLS stream_low.m3u8
  Credit to: [email protected]
0 notes
andrewjsinclair · 11 years
Link
Useful transcode settings from the Miro encoder with a good list of some mobile profiles.
0 notes
andrewjsinclair · 11 years
Text
Encoding HLS with ffmpeg
For starters here is the command to create a stream that is GOP aligned, that is has keyframes at regular intervals that can be nicely segmented. It is recommended to pull down and compile the latest version of ffmpeg for this as some of the distros can be a bit out of date.
ffmpeg -y -i %(filename)s -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r %(fps)s -profile:v baseline -b:v %(bitrate)sk -maxrate %(bitrate)sk  -force_key_frames %(keyframe_str)s -s %(width)sx%(height)s %(target_dir)s%(newFile)s
The s%(filename) are in Python format where the %s(var) bit gets replaced with your value.
For example:
ffmpeg -y -i infile.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 2000k -maxrate 2500k  -force_key_frames 50s -s 640x360 /tmp/newfile.ts
I like to do segmenting as a second step just to keep the whole process a bit cleaner, especially if you want to produce multiple formats off the same initial encode:
ffmpeg -y -i %(target_dir)s%(filename)s -codec copy -map 0 -f segment -segment_list %(target_dir)sindex_%(bitrate)s.m3u8 -segment_time %(segment_size)s  -segment_list_type m3u8 %(filenameNoExt)s_%(count)s.ts
Or you could wrap it all into one command e.g.
ffmpeg -y -i %(filename)s -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r %(fps)s -profile:v baseline -b:v %(bitrate)sk -maxrate %(bitrate)sk  -force_key_frames %(keyframe_str)s -s %(width)sx%(height)s %-f segment -segment_list %(target_dir)sindex_%(bitrate)s.m3u8 -segment_time %(segment_size)s  -segment_list_type m3u8 %(filenameNoExt)s_%(count)s.ts
Working example:
ffmpeg -y -i infile.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -maxrate 2000k -force_key_frames 50 -s 640x360 -map 0 -flags -global_header -f segment -segment_list /tmp/index_1500.m3u8 -segment_time 10 -segment_format mpeg_ts -segment_list_type m3u8 /tmp/segment%05d.ts
Here is an example of capturing from the desktop Linux and streaming straight to a local web server configured for low latency:
ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -x264opts keyint=25 -s 640x360 -map 0 -flags -global_header -f segment -segment_list index_1500.m3u8 -segment_time 1 -segment_format mpeg_ts -segment_list_type m3u8 -segment_list_flags +live -segment_list_size 2 segment%05d.ts
Tested with:
ffmpeg version N-51554-g1c0d8f2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr  7 2013 18:35:14 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --enable-libx264 --enable-libfaac --enable-nonfree --enable-gpl
  libavutil      52. 24.100 / 52. 24.100
  libavcodec     55.  2.100 / 55.  2.100
  libavformat    55.  1.100 / 55.  1.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 49.100 /  3. 49.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Hyper fast Audio and Video encoder
0 notes
andrewjsinclair · 11 years
Text
Video Players for Android
Android suffers from not having a good across the board player, especially for HLS. There appear to be a few approaches:
Chance it with the native player
Link through to a VLC variant using Android NDK/JNI
Link through to a ffmpeg variant using Android NDK/JNI
Run a HLS proxy that converts the HLS to RTSP and then sends RTSP to the native player (SOL HLS does this)
NXP Cinexplayer
Sol HLS Player
Looked promising as it is supposed to just pickup the mime-type and then control the playback but had trouble getting it to pick up the stream.
Note that if you want to like to a live HLS stream use the intent httplive:// works very well and even with a token protected Akamai stream.
After more testing am less convinced on this one as it takes the stream and then does a live transmux from HLS to RTSP and pipes that to the local player. The end result can be quite a lot of pixelisation.
Ooyala Hook
Only works with the Ooyala backend and appears to be based on the VisualOn player.
VisualOn
NXPlayer
ffmpeg/libav variant
MoboPlayer
Nexstreaming
Vitamio
Hoperun
http://www.hoperun.com/hoperun/
ffmpeg/libav
DIY Ffmpeg!
0 notes
andrewjsinclair · 11 years
Link
0 notes
andrewjsinclair · 11 years
Text
Building a VSFTPD server on EC2 Linux
For starters do the following in the AWS console:
First create a new server e.g. use the Default 64 bit Amazon Linux instance
Create a new security group when you create the server
To the 
Create an Elastic IP and associate with the instance
First install vsftpd: sudo apt-get install vsftpd
Edit /etc/vsftpd.conf and make sure you have the following settings
anonymous_enable=no
local_enable=yes
write_enable=yes
chroot_local_user=yes
userlist_file=/etc/vsftpd.userlist
userlist_enable=YES
userlist_deny=NO
pasv_max_port=41000
pasv_min_port=40000
port_enable=YES
pasv_enable=YES
pasv_address=<Elastic IP address>
Adding a user:
Create a home dir: sudo mkdir /home/ftpuser
Create the user account: sudo useradd -d /home/ftpuser
Set the users passwd: sudo passwd ftpuser
Change owner of the dir: sudo chown ftpuser /home/ftpuser
Add the user to the allowed ftp user list: sudo vi /etc/vsftpd.userlist
VSFTPD doesn't allow writable root by default so change the permissions on the user root: sudo chown u-w /home/ftpuser
0 notes
andrewjsinclair · 11 years
Text
Using ffmpeg to encode SBS to Anaglyph
ffmpeg -i sbs.mp4 -vf mp=stereo3d -acodec copy -threads 10 -b:v 10000k -preset ultrafast -vcodec libx264 ~/test2.mkv
http://delogics.blogspot.it/2012/01/sbspolarizedstereo-3d-to-alaglyphred.html
And more good info this time using mencoder:
http://www.noah.org/wiki/Mplayer_notes
0 notes
andrewjsinclair · 12 years
Text
Using ffprobe to evaluate keyframes
ffprobe is quite a good little tool for evaluating keyframes in a video and here is a simple statement that can show you an easy way to view the GOP structure of a video:
ffprobe -show_frames out_gop12.ts |grep 'media_type=video\|pict_type\|coded_picture_number'|less
Now on doing this I am seeing that ffmpeg and x264 aren't necessarily following the GOP structure that I have set which has a max keyframe distance of 12.
Sample output:
media_type=video
pict_type=I
coded_picture_number=0
media_type=video
pict_type=P
coded_picture_number=1
media_type=video
pict_type=I
coded_picture_number=2
media_type=video
pict_type=P
coded_picture_number=3
media_type=video
pict_type=P
coded_picture_number=4
media_type=video
pict_type=P
coded_picture_number=5
media_type=video
pict_type=B
coded_picture_number=7
media_type=video
pict_type=P
coded_picture_number=6
media_type=video
pict_type=B
coded_picture_number=10
media_type=video
pict_type=B
coded_picture_number=9
media_type=video
pict_type=B
coded_picture_number=11
media_type=video
pict_type=P
coded_picture_number=8
media_type=video
pict_type=B
coded_picture_number=14
Here is a good post with some more info on the topic
http://forums.creativecow.net/thread/291/71
I have also created a little Python script that will process the output to show you when keyframes occur:
#!/usr/bin/python
import os
import re
import sys
import subprocess
#infile = sys.argv[1]
infile= "/tmp/ffmpeg_main_profile/out_gop12.ts"
lines_past_type = 20
line_count = 0
print_line = False
gop = 12
frame = 0
found_iframe = False
cmd = "ffprobe -show_frames %s" % infile
# -print_format json
process = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE \
                               ,cwd=target_dir)
while True:
  line = process.stdout.readline()
  if line != '':
    #the real code does filtering here
    #print line.rstrip()
    if (line.rstrip()=="media_type=video"):
        print_line = True
    if (print_line and (line_count < lines_past_type)):
                     #print line.rstrip()
        if re.match(r'pict_type=I.*',line):
            found_iframe = True
            #print line.rstrip()
        match = re.match(r'coded_picture_number=(.*)',line)
        if (match):
            frame =  match.group(1)
            if (found_iframe):
                print "I Frame: %s" % frame
                div12 = float(frame) / 12
                found_iframe = False
                 line_count+=1
        if (line_count >= lines_past_type):
            print_line = False
            line_count = 0
  else:
    break
0 notes
andrewjsinclair · 12 years
Link
I really liked this post as it covered both the high level as well as diving down into the details of what you should be doing with x264 encoding for both file based and linear
0 notes
andrewjsinclair · 12 years
Link
A look at how best to capture output from ffmpeg uing Python which can be a complex activity.
0 notes
andrewjsinclair · 12 years
Link
Great list of ffmpeg commands including some advanced features like HLS segmentation
0 notes
andrewjsinclair · 12 years
Link
FFmpeg Howto
Table of Contents
Encoding:
H.264 Long GOP
D10 (aka Sony IMX)
XDCAM HD 50Mbps in QuickTime (for Final Cut Pro import)
DVCAM / DVCPRO25 / DVCPRO50
VC-3 (aka Avid DNxHD)
MPEG-2 I-frame only in Highest Quality
MPEG-2 Long GOP
MJPEG in Highest Quality
Muxing and Wrapping:
D10 into QuickTime (for Final Cut Pro import)
MPEG-2 Program Stream
Demuxing and Unwrapping:
MPEG-2 Program Stream
Timecode Management:
MPEG-2 Start Timecode
Misc:
Audio Volume Modification
Input Stream Selection
Sub-clip Creation
Make a Video File from a Single Frame
H.264 Long GOP Encoding
1-pass encoding:  ffmpeg -i <input_file> -vcodec libx264 -b <video_bitrate> -g <gop_size> -bf 3 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1 -acodec libfaac -ab <audio_bitrate> output.mp4  2-pass encoding:  ffmpeg -y -i <input_file> -pass 1 -vcodec libx264 -b <video_bitrate> -g <gop_size> -bf 3 -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method umh -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs -trellis 1 -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -acodec libfaac -ab <audio_bitrate> output.mp4  ffmpeg -y -i <input_file> -pass 2 -vcodec libx264 -b <video_bitrate> -g <gop_size> -bf 3 -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method umh -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs -trellis 1 -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -acodec libfaac -ab <audio_bitrate> output.mp4 
D10 (aka Sony IMX) Encoding
ffmpeg -i <input_file> -vcodec mpeg2video -r 25 -pix_fmt yuv422p -minrate 50000k -maxrate 50000k -b 50000k -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -ps 1 -qmin 1 -qmax 3 -top 1 -bufsize 2000000 -rc_init_occupancy 2000000 -rc_buf_aggressivity 0.25 -an output.m2v  Notes :  - Only works for 25 fps content.  - Change minrate, maxrate and b values to 30000k / 40000k / 50000k in order to produce 30/40/50 Mbps D10 essence.  - Set bufsize and rc_init_occupancy values to 1200000 / 1600000 / 2000000 for 30/40/50 Mbps D10 essence.  - Set qmax value to 8 / 3 / 3 for 30/40/50 Mbps D10 essence.  - Add the -padtop 32 option if you want to produce a 720x608 D10 image size from a 720x576 source. 
XDCAM HD 50Mbps in QuickTime (for Final Cut Pro import)
ffmpeg -i <input_file> -pix_fmt yuv422p -vcodec mpeg2video -flags +ildct+ilme -top 1 -dc 10 -flags2 +ivlc+non_linear_q -qmin 1 -lmin '1*QP2LAMBDA' -vtag xd5c -rc_max_vbv_use 1 -rc_min_vbv_use 1 -b 50000k -minrate 50000k -maxrate 50000k -bufsize 36408333 -bf 2 -aspect 16:9 -acodec pcm_s16be -f mov output.mov -newaudio 
DVCAM / DVCPRO25 / DVCPRO50 Encoding
ffmpeg -i <input_file> -pix_fmt yuv420p output_DVCAM.dv  ffmpeg -i <input_file> -pix_fmt yuv411p output_DVCPRO25.dv  ffmpeg -i <input_file> -pix_fmt yuv422p output_DVCPRO50.dv 
VC-3 (aka Avid DNxHD) Encoding
ffmpeg -i <input_file> -vcodec dnxhd -b <bitrate> -an output.mov  Notes :  - <bitrate> can take the following values : 36M, 60M, 90M, 120M, 185M ( please refer to the following table ).  - Add the following option for interlaced modes : -flags +ildct  - Add the following option for best quality mode ( very slow ! ) : -mbd rd  Supported Resolutions :  Project FormatResolutionFrame SizeBitsFPS<bitrate>1080i / 59.94DNxHD 2201920 x 1080829.97220M1080i / 59.94DNxHD 1451920 x 1080829.97145M1080i / 50DNxHD 1851920 x 1080825185M1080i / 50DNxHD 1201920 x 1080825120M1080p / 25DNxHD 1851920 x 1080825185M1080p / 25DNxHD 1201920 x 1080825120M1080p / 25DNxHD 361920 x 108082536M1080p / 24DNxHD 1751920 x 1080824175M1080p / 24DNxHD 1151920 x 1080824115M1080p / 24DNxHD 361920 x 108082436M1080p / 23.976DNxHD 1751920 x 1080823.976175M1080p / 23.976DNxHD 1151920 x 1080823.976115M1080p / 23.976DNxHD 361920 x 1080823.97636M1080p / 29.7DNxHD 451920 x 1080829.9745M720p / 59.94DNxHD 2201280x720859.94220M720p / 59.94DNxHD 1451280x720859.94145M720p / 50DNxHD 1751280x720850175M720p / 50DNxHD 1151280x720850115M720p / 23.976DNxHD 901280x720823.97690M720p / 23.976DNxHD 601280x720823.97660M
MPEG-2 I-frame only Highest Quality Encoding
ffmpeg -i <input_file> -vcodec mpeg2video -pix_fmt yuv422p -qscale 1 -qmin 1 -intra -an output.m2v 
MPEG-2 Long GOP Encoding
ffmpeg -i <input_file> -vcodec mpeg2video -b <video_bitrate> -g <gop_size> -bf 2 -b_strategy 1 -acodec mp2 -ab <audio_bitrate> -f vob output.mpg 
MJPEG in Highest Quality
ffmpeg -i <input_file> -vcodec mjpeg -qscale 1 -an output.avi 
D10 into QuickTime Wrapping
ffmpeg -i <input_file> -vcodec copy -acodec pcm_s16le -vtag mx5p -vbsf imxdump output.mov  Notes :  - This feature needs a patched version of FFmpeg not available in the current SVN, please contact Baptiste Coudurier for more information.  - Set -vtag to mx3p / mx4p / mx5p for D10 30/40/50 PAL or mx3n / mx4n / mx5n for D10 30/40/50 NTSC.  - Input D10 image size must be 720x608 ( use -padtop 32 option during D10 encoding if the original image size is 720x576 ).  - Final Cut Pro compliant. 
MPEG-2 Program Stream Muxing
ffmpeg -genpts 1 -i ES_Video.m2v -i ES_Audio.mp2 -vcodec copy -acodec copy -f vob output.mpg  Note : In order to mux multiple audio tracks into the same file :  ffmpeg -genpts 1 -i ES_Video.m2v -i ES_Audio1.mp2 -i ES_Audio2.mp2 -vcodec copy -acodec copy -f vob output.mpg -newaudio  Note : In order to remux a PS file with multiple audio tracks :  ffmpeg -i input.mpg -vcodec copy -acodec copy -f vob output.mpg -acodec copy -newaudio 
MPEG-2 Program Stream Demuxing
ffmpeg -i input.mpg -vcodec copy -f mpeg2video ES_Video.m2v -acodec copy -f mp2 ES_Audio.mp2  Note : This also works for files containing multiple audio tracks :  ffmpeg -i input.mpg -vcodec copy -f mpeg2video ES_Video.m2v -acodec copy -f mp2 ES_Audio1.mp2 -acodec copy -f mp2 ES_Audio2.mp2 
MPEG-2 Start Timecode
ffmpeg -i <input_file> -timecode_frame_start <start_timecode> -vcodec mpeg2video -an output.m2v  Note : Start timecode is set as number of frames. For instance, if you want to start at 18:12:36:15, you will have to set -timecode_frame_start to 1638915 ( for 25 fps content ). 
Audio Volume Modification
ffmpeg -i <input_file> -vol <audio_volume> -acodec <audio_codec> <output_file> 
Input Stream Selection
ffmpeg -i input.vob -map 0:2 -acodec aac -ab <audio_bitrate> -vn output.mp4  Transcode audio stream #0:2. 
Sub-clip Creation
ffmpeg -i <input_file> -ss <timecode> -t <timecode> -vcodec copy -acodec copy <output_file> 
Make a Video File from a Single Frame
ffmpeg -loop_input -vframes <number_of_frames> -i <input_file> <output_file> 
Sponsor: SmartJog  Please submit new command lines to Olivier Amato
0 notes
andrewjsinclair · 12 years
Link
0 notes
andrewjsinclair · 12 years
Link
0 notes
andrewjsinclair · 12 years
Text
Encoding HLS in ffmpeg
Simple segmentation without multi-rate or re-encode
ffmpeg -i 67420370.mp4 -codec copy -map 0 -f segment -segment_list index.m3u8 -segment_time 10 -bsf h264_mp4toannexb -segment_list_type m3u8 out%03d.ts
0 notes
andrewjsinclair · 12 years
Link
Using the well known ffmpeg/x264 for encoding and mp4split to create the fragmented PIFF files and manifests.
0 notes
andrewjsinclair · 12 years
Link
Ago particle on setting up pfsense which looks like an good way to test adaptive bitrate performance of a device. Lots of other good advice for STB dev on there as well.
0 notes