# more options for ffmpeg recording



## pkv (Sep 28, 2016)

Hello,

this is a series of suggestions for a better use of ffmpeg capabilities.
(this is related to this thread: https://obsproject.com/forum/threads/protocol-support-on-obs-multiplatform-mpeg-dash-hls.22969/ )

*(1) better codec selections (at least for mpegts):*

At the moment when selecting any given muxer in recording > Custom Output (FFmpeg), a default encoder is selected but there is not always freedom to select another compatible codec.

Ex: mpegts ===> video encoder is only mpeg2video and audio encoder is: mp2

But mpegts is compatible with x264 and aac ... The difference in quality is huge ...

*(2) increase the number of audio tracks to at least 16 or better 32:*

case use: SDI with embedded audio (16 channels usually) corresponding to various languages, commentary, etc ...
case use: surround audio recorded in different channels

coupled to mpegts (see (1) ) , this is useful in professional settings (stb iptv dvb)


*(3) enable custom filter options on ffmpeg input:*

case use: -filter_complex on audio and video 
One would need to pass options to ffmpeg here: ffmpeg -i INPUT [HERE] -c:v [video codec options] -c:a [audio options] -f muxer [ muxer options] OUTPUT

Ex: ffmpeg -channels 8 -f decklink -i Decklink-INPUT -filter_complex "[0:a]pan=mono|c0=c0[a0];[0:a]pan=mono|c0=c1[a1];[0:a]pan=mono|c0=c2[a2];[0:a]pan=mono|c0=c3[a3];[0:a]pan=mono|c0=c4[a4];[0:a]pan=mono|c0=c5[a5];[0:a]pan=mono|c0=c6[a6];[0:a]pan=mono|c0=c7[a7]" /
-c:v ...
-c:a ...
This command separates for instance a 7.1 sourround audio in 8 streams (+ video stream).
This can be useful for mepgts or mkv (multi-language) for sdi embedded audio input
But all the filters of ffmeg are available ... quite powerful.

*(4) enable tee muxer*
The tee muxer is quite convenient in that it enables multiple outputs.
case_use: This would allow streaming to various destinations, URL and files (streaming and recording).
case_use: this would allow more muxing options (the video and audio streams can be muxed differently on the various tee muxer outputs)
The tee muxer does a single encode for all the outputs so it is better for the CPU.

Maybe a way to implement all this in a single stroke would be the ability to pipe OBS with ffmepg scripts: 
obs | ffmpeg -i - -c:v etc 
OBS would specify the inputs and ffmpeg process them.


----------



## Jack0r (Oct 1, 2016)

my guess is that OBS "asks" ffmpeg which encoders should be available, but I agree that it would be awesome to have the option to freely choose it when necessary. Its probably easily done but Jim will have to take a look at it.
Currently there is no plan to increase the number of channels, there was a discussion about adding channels but it was decided to do this probably later on in the future.
not totally sure what you mean with ffmpeg input in this case. generally I think its not a bad idea to have the option to use filters that ffmpeg offers.
again, not a bad idea and definitely something for the future of the custom ffmpeg output.


----------



## pkv (Oct 1, 2016)

Hi Jack0r,
by 3. I meant: given an INPUT provided by OBS to ffmpeg , *enable ffmpeg audio and video filters*, which would therefore come in the pipeline after OBS filters, rescaling, overlays, etc.
thanks for your feedback
:)


----------



## pkv (Oct 1, 2016)

on suggestion 1: I checked that indeed, the default codec for a given muxer is actually specified by ffmpeg
ex: ffmpeg -h muxer=mpegts
shows 
Default video codec: mpeg2video.
    Default audio codec: mp2.


----------



## Bubbles00 (Oct 12, 2016)

Hello Jack0r,

We are as well very much interested in all the features listed above. 
We have an end-to-end solution for multilingual streaming. But we are missing a GUI for the broadcast client.

Ultimately OBS streaming would be configurable in advanced mode, like recording. So "start streaming" would lauch a MPEG-TS stream and "start recording" would record a multi-track file locally.
But features 1 to 4 listed above would already bring us very far...

Could a donation speed up these specific features? Or is it possible to hire an OBS developer for this job?


----------



## Osiris (Oct 12, 2016)

A donation will not speed up anything.


----------



## pkv (Feb 18, 2017)

*partial follow-up:*

regarding suggestion (1), I noticed today a tweak which allows h264 with mpeg-ts output for ffmpeg recording:
specify the codec on basic.ini in the appdata>roaming>obs-studio profiles folder.
This forces the video codec to h264 while the setup through the GUI allows only mp2.


----------



## ICAN (Feb 18, 2017)

Thanks PKV.
From what I see in basic.ini is that the codec and container show up as h.264, as listed below:

_FFFormat=h264
FFFormatMimeType=
FFExtension=h264,264
FFRescale=true
FFVEncoder=libx264
FFAEncoder=_​were you also able to note any quality difference also?
Can you share any test results?


----------



## ICAN (Feb 18, 2017)

Edit:
PKV, i am not sure basic.ini is getting updated. please see my ectract:
_[General]
Name=Untitled

[Output]
Mode=Advanced

[SimpleOutput]
VBitrate=800
ABitrate=64
RecFormat=mp4
UseAdvanced=true

[AdvOut]
TrackIndex=1
RecType=FFmpeg
RecTracks=1
FFOutputToFile=false
FFVEncoderId=28
FFAEncoderId=0
FFAudioTrack=1
Rescale=true
FFFormat=h264
FFFormatMimeType=
FFExtension=h264,264
FFRescale=true
FFVEncoder=libx264
FFAEncoder=
FFURL=udp://239.1.1.1:9000
Track1Bitrate=64

[Audio]
ChannelSetup=Mono

[Video]
OutputCX=1280
OutputCY=720_

However, I have configured the address to be 225.1,1.1: 9000 and not 239.1.1.1, and also the container to be mpegts. Even then the above capture shows h264. This is strange.

Further, as I understand we need ts container, but x264 encoder. Please confirm that indeed you had this combination.


----------



## pkv (Feb 18, 2017)

here's how my basic ini file looks and in bold is what I manually changed from what the GUI records in the file:

[AdvOut]
RescaleRes=2560x1440
TrackIndex=4
RecType=FFmpeg
RecRescaleRes=2560x1440
RecTracks=15
FFOutputToFile=false
FFRescaleRes=2560x1440
*FFVEncoderId=28
FFAEncoderId=86018*
FFAudioTrack=6
FFURL=udp://xxxxxxx:10000
FFFormat=mpegts
FFFormatMimeType=video/MP2T
FFVBitrate=2500
FFVEncoder=libx264
FFVCustom=-map 0:v -c:a libx264  -s 1920x1080 -r 30 -pix_fmt yuv420p -preset veryfast -b:v 2500k -profile:v high -g 60
FFABitrate=64
*FFAEncoder=aac*
FFACustom=
*FFExtension=ts*
RecEncoder=obs_x264
Track1Bitrate=64
RecFormat=ts
Track2Bitrate=64
FFMCustom=

After editing, I start OBS-studio and press 'start recording' ;
the quality is fine


----------



## ICAN (Feb 18, 2017)

Edit 2:

_[General]
Name=1

[Output]
Mode=Advanced

[AdvOut]
TrackIndex=1
RecType=FFmpeg
RecFilePath=udp://@235.1.1.1:9000
RecFormat=mp4
RecEncoder=obs_qsv11
RecTracks=1
FFOutputToFile=false
FFURL=udp://225.1.1.1:9000
FFFormat=mpegts
FFExtension=ts,m2t,m2ts,mts
FFVBitrate=800
FFVEncoderId=2
FFABitrate=64
FFAEncoderId=86016
FFAudioTrack=1
FFRescale=false
FFRescaleRes=872x490
Encoder=obs_x264
ApplyServiceSettings=true
FFVEncoder=mpeg2video
FFFormatMimeType=video/MP2T
FFAEncoder=mp2

[Video]
OutputCX=544
OutputCY=306
_
finally Managed to locate the right file.

*Q: How to edit or make the system change in the encoder type?*


----------



## ICAN (Feb 18, 2017)

OK, Just saw your input. let me revert


----------



## pkv (Feb 18, 2017)

i'll post a detailed walkthrough later today; after streaming in udp, I recorded to a file; I was testing whether a multi-track record can be done in ts, it worked
The files are in mpegt-s muxer + x264 + aac 
check the captures (mediainfo of ts file created with mp4 and aac with 4 stereo tracks)

 
After doing that, I messed the parameters so I have not recovered the udp setup yet; I'll do it again and post the right changes to do to the basic.ini file when I find the right recipe again, so discard the previous posts.


----------



## pkv (Feb 18, 2017)

ok got the recipe back:

1) setup on Setting > output > recording > Output to URL
==> enter your udp address
==> select container format: mpegts
video encoder and audio encoder are then : mp2

2) locate your profile folder  or : File > Show Profile folder

3) exit OBS-Studio

4) edit as follows the basic.ini file (*bold entries*):

[General]
Name=local

[Output]
Mode=Advanced

[AdvOut]
RescaleRes=2560x1440
TrackIndex=2
RecType=FFmpeg
RecRescaleRes=2560x1440
RecTracks=15
FFOutputToFile=false
FFRescaleRes=2560x1440
*FFVEncoderId=28
FFAEncoderId=86018*
FFAudioTrack=2
FFURL=udp://server.fbt-asso.org:10000
FFFormat=mpegts
FFFormatMimeType=video/MP2T
FFVBitrate=2500
*FFVEncoder=libx264*
FFVCustom=-map 0:v -c:v libx264  -s 1920x1080 -r 30 -pix_fmt yuv420p -preset veryfast -b:v 2500k -profile:v high -g 60
FFABitrate=64
*FFAEncoder=aac*
FFExtension=ts,m2t,m2ts,mts
RecEncoder=obs_x264
Track1Bitrate=64
RecFormat=ts
Track2Bitrate=64
FFACustom=-c:a aac -ab 128k -ac 2

[Video]
BaseCX=1920
BaseCY=1080
OutputCX=1280
OutputCY=720
FPSType=1
FPSInt=25

[SimpleOutput]
UseAdvanced=true
RecFormat=ts
RecQuality=Small


5) start OBS-studio
6) crucial step ==> click on 'Start Recording' (don't go to Settings to check that the parameters have been updated, it doesn't work, I was stuck on that this evening when starting to recover the tweak)
7) this connects and you should have some stream
8) now you can click on Setting > output > recording , you should have the following screen, tada, enjoy !!! :)


----------



## pkv (Mar 4, 2017)

mpegts with x264 aac officially enabled in obs 18 thanks to derrod !!!

But the huge news is VST support !
so now, please increase the number of tracks supported!
asio support as in audacity (not bundled due to licensing reasons) would be a huge huge plus.

since obs 18, mpegts supports x264 + aac thanks to derrod !

UPDATE:
mpeg-ts tcp protocol working in addition to mpeg-ts udp
BUT multichannel audio does not while it works when recording to a file; only the last two channels are taken into account ...


----------



## Othni (Nov 20, 2018)

I need to use the ffmpeg option  "localaddr=addr" to specify the network interface to use for broadcast to multicast address.

How do I do this?


----------



## Othni (Nov 30, 2018)

Othni said:


> I need to use the ffmpeg option  "localaddr=addr" to specify the network interface to use for broadcast to multicast address.
> 
> How do I do this?


Never mind, I just created a static route for the multicast traffic and this worked for me.


----------



## nak1 (Dec 3, 2018)

Guys, 

I'm running into the same issue where i have a raw stream that I need to convert into MP4 (within OBS) but when I try to select the MP4 I still have to preform the hack mentioned above to the basic.ini file.  It sounds like this is no longer needed, but I have the latest version of OBS (version 22.0.2) and it doesn't allow for MP4 when mepgts is the content container.  Anyone has any idea why that is the case?


----------



## pkv (Dec 4, 2018)

hi 
you do not make sense; mpegts and mp4 are both containers;
you meant perhaps x264 with mpegts ?
if so, the hack is not needed; you just need to tick 'Show all codecs"


----------



## ICAN (Sep 6, 2019)

Hello PKV, Great work here!
I need some help on this issue, if you would please.
Using the setup and guidance above, on atest setup I have connected two PCs directly, on the same subnet. Tested the connectivity through ping. 
I am able to stream out the multicast (mpeg-ts, x264, aac), I can see the bits streaming out in the network interface, but the video does not show up in the receving PC on VLC. I am see the receiver counter ticking which means conenction is made and bits are accepted but I seem to be getting a TS container error on the VLC debug console. 

Any idea or help ?
Anybody who has received obs/multicast on VLC should be able to guide as well.


----------



## ICAN (Sep 6, 2019)

If this helps..


----------



## pkv (Sep 7, 2019)

i've only tested with unicast, not multicast. Not sure i understand the ts decoding issue with vlc.


----------



## ICAN (Sep 7, 2019)

What was your setup when you did Unicast from OBS to a PC with VLC on the LAN


----------



## pkv (Sep 7, 2019)

use the ip of your target pc and any port; in my case i've used it only on same pc so used  127.0.0.1 or on the wan, where i've used the public ip of my server


----------



## ICAN (Jan 16, 2020)

Hello pkv.
I have an issue where you could possibly help:
I am able to multicast using custom ffmpeg, but then not able to also record at the same time. Is there a way that we can stream to a path as well as record


----------



## pkv (Jan 16, 2020)

ICAN said:


> Hello pkv.
> I have an issue where you could possibly help:
> I am able to multicast using custom ffmpeg, but then not able to also record at the same time. Is there a way that we can stream to a path as well as record


not with current obs.
I have some code which adds outputs and allows that but I haven't released it and I have no plan to do so (needs debugging and polishing and I have no time for that).
It is planned in Obs to enable multiple streaming/recording outputs. But won't be any soon. I'd say it'll be in one year minimum, not earlier.


----------



## Vladimir Sobolev (Apr 18, 2020)

So, any options to add *-vf* params to recording params for ffmpeg?  I want to rotate recorded video for example (rebroadcast it to rtmp in portrait mode)


----------



## pkv (Apr 18, 2020)

Vladimir Sobolev said:


> So, any options to add *-vf* params to recording params for ffmpeg?  I want to rotate recorded video for example (rebroadcast it to rtmp in portrait mode)


no, avfilter library is not used in obs.
You'll have to rotate on your own, for instance with an ffmpeg instance in between obs and your ingest server.


----------



## Barabba (Apr 25, 2020)

I have the same problem, it writes the file correctly but with the same parameters it dowsn't stream video, only audio. I've tried also default mp2 encoders, same result, doesn't stream video


----------



## Barabba (Apr 25, 2020)

the solution is add ?pkt_size=1316  for example udp://iphost:port?pkt_size=1316


----------



## Vladimir Sobolev (Apr 29, 2020)

pkv said:


> no, avfilter library is not used in obs.
> You'll have to rotate on your own, for instance with an ffmpeg instance in between obs and your ingest server.


Can you please add avfilter library and maybe font/text library to future ffmpeg compile instructions for OBS releases? Its will be very useful to expose these settings to custom FFMPEG output.


----------



## pkv (Apr 29, 2020)

no it's not a simple as just compiling avfilter library. There's some code work to do in UI and backend. I doubt it'll be done. You'll have to do it yourself or hire a dev to do it (won't be cheap).


----------



## Stas Fomin (Jul 22, 2021)

On version 26.1.2 I still cannot add «filter_complex» to «Advanced FFmpeg Recording»
I tried to add « -filter_complex "setpts=PTS/1.4;atempo=1.4" » to «Video Encoder Settings» but get «Failed to set "setpts=PTS/1.4;atempo=1.4"» in logs.

So is it possible now (2021-07) to somehow add « -filter_complex "setpts=PTS/1.4;atempo=1.4" » to processing output?


----------



## pkv (Jul 22, 2021)

Stas Fomin said:


> On version 26.1.2 I still cannot add «filter_complex» to «Advanced FFmpeg Recording»
> I tried to add « -filter_complex "setpts=PTS/1.4;atempo=1.4" » to «Video Encoder Settings» but get «Failed to set "setpts=PTS/1.4;atempo=1.4"» in logs.
> 
> So is it possible now (2021-07) to somehow add « -filter_complex "setpts=PTS/1.4;atempo=1.4" » to processing output?


Nope, it's not possible indeed.
I doubt this will be implemented. Obs does not use ffmpeg per se but relies on the ffmpeg libraries avcodec.lib, abformat.lib, swresample.lib etc So don't expect ffmpeg cli syntax and caps to carry over to obs. It'd be a bit too much work.
Note that ffmpeg audio filters have been ported as a plugin though.


----------

