Log in

View Full Version : New tool to change SAR in H264 bitstream


Pages : 1 2 3 [4] 5

WCVanHorne
18th December 2011, 03:23
So I must be doing something really dumb. "muxerfps" does not seem to work. My command:

ffmpeg -i title01.mkv -vcodec copy -acodec copy -vbsf h264_changesps=sar=x:y -muxerfps (24000/1001) fix.mkv

Gives the error:

[Eval @ 0022fcf8] Undefined constant or missing '(' in 'muxerfps'

sneaker_ger
18th December 2011, 10:10
Don't use brackets.

WCVanHorne
18th December 2011, 17:12
Whoops, I actually wasn't initially using brackets. I accidentally cut 'n pasted the line where I had tried them due to the error. This command gives the same error:

ffmpeg -i title01.mkv -vcodec copy -acodec copy -vbsf h264_changesps=sar=x:y -muxerfps 24000/1001 fix.mkv

sneaker_ger
18th December 2011, 17:56
My bad, I jumped the gun, that error message is about a missing "(", not an unknown char. I downloaded the newest build and I have the same problem with that.

WCVanHorne
23rd December 2011, 01:41
So is there any way to get this working to correct the SAR in an mkv file? When I run without this flag it creates a file but with a completely wacky frame rate.

wOxxOm
23rd December 2011, 09:19
I second WCVanHorne - I've had to extract timecodes from original mkv with mkvextract and then mux them in using mkvmerge.

sneaker_ger
23rd December 2011, 11:30
Yes, download an older build or work on the raw stream, then mux with mkvmerg, as suggested by wOxxOm.

We'll have to wait for roozhou to take a look at it.

WCVanHorne
23rd December 2011, 15:19
Yes, download an older build ...

Ah.. It was working at some point then. Any particularly recommended build or just work my way back until it starts working?

D9JK
19th January 2012, 20:04
I've been looking for a tool to change only the frame rate setting in my video files, without a time-consuming re-encoding process, and it seems this one could be what I've been looking for. After reading this thread twice and making tests, I'm still having trouble though.

If I've understood correctly, it's not enough to change the "container frame rate" setting: I would also need to change the "video stream frame rate" setting. And if I've also understood correctly, to assign a new value for "video stream frame rate", I would need to use the muxerfps option? But I've been trying various ways, and I can't get it to work (it seems a few others are having the same issue).

Examples:

1) ffmpeg.exe -i Input.mkv -vcodec copy -an -vbsf h264_changesps=fps=4000:1000 Test.mkv

This outputs "Test.mkv", which VLC Player reports to have a frame rate of 4 fps, but which still seems to play at the original 20 fps.

2) ffmpeg.exe -i Input.mkv -vcodec copy -an -vbsf h264_changesps=fps=4000:1000 -muxerfps 4000:1000 Test.mkv

This never finishes, except with an error message stating:

Undefined constant or missing '(' in 'muxerfps'
Incorrect value for muxerfps: muxerfps

Any ideas? Or is there simply a bug that needs to be fixed first? Thanks for any help!

b66pak
19th January 2012, 20:20
for the 1st problem: this line change the fps in the stream BUT the timecodes in the container are preserved...if you want new timecodes use this line to demux to raw and then remux with the fps you want:

ffmpeg -i input.mkv -vcodec copy -an -vbsf h264_changesps=fps=4000:1000 -vbsf h264_mp4toannexb=norepeatheader output.h264

you will get output.h264 at 4fps...

for the 2nd problem: -muxerfps is broken
_

D9JK
19th January 2012, 21:39
Hmm, would the -muxerfps option be of any use for what I'm trying to accomplish here, after all? What is it used for exactly?

sneaker_ger
20th January 2012, 00:04
You're probably better off changing the framerate with mkvmerge (GUI).

D9JK
20th January 2012, 09:53
I use mkvmerge a lot for merging and splitting videos, but I wasn't aware that it can modify the frame rate as well. Thanks for the tip - I'll take a look.

bernd_b
20th January 2012, 13:42
To my knowledge, mkvmerge only changes the given frame rate information of the container, the h.264-Stream itself keeps its frame rate.

At least that's what I see when I examine the files using the tool mediainfo.

And some (software)player use the framerate of the container (hopefully the audio fits then), my hardwareplayer don't.

Chug a Bug
2nd July 2012, 15:56
I'm having some problems with the SAR change in this program, I have some videos in h264 that I'd like to change from a 4:3 ratio to a 16:9 SAR.

My source video is 720x576, I'd like to change the SAR from 4:3 to 16:9 but this program comes up with all kinds of odd aspect ratios, this particular one results in a SAR of 2.222. I have other 4:3 aspect videos but different pixel dimensions and they also come up with odd aspect ratios, but different -

The line I'm using is -

ffmpeg -i video.mkv -vcodec copy -acodec copy -vbsf h264_changesps=sar=16:9 video2.mkv

I've tried demuxing to elementary streams but the result is the same

SeeMoreDigital
2nd July 2012, 16:26
The line I'm using is -

ffmpeg -i video.mkv -vcodec copy -acodec copy -vbsf h264_changesps=sar=16:9 video2.mkv

Try an SAR value of 64:45 with your 720x576 sources...

Chug a Bug
5th July 2012, 18:44
:thanks:

That worked, do you mind explaining how you calculated that ratio?

b66pak
5th July 2012, 19:42
sar (aka par) can be calculated like this:
sar = dar/resolution
example far you case:
sar = (16:9)/(720/576) = (16:9)/(5:4) = 64:45
_

SeeMoreDigital
5th July 2012, 20:30
:thanks:

That worked, do you mind explaining how you calculated that ratio?
I used the ARS Calculator (http://forum.doom9.org/showthread.php?t=107039)...

http://i45.tinypic.com/1q0bja.png

mandarinka
6th July 2012, 02:08
I recommend this great calculator: http://ps-auxw.de/cgi-bin/ar-calc.pl

Chug a Bug
9th July 2012, 11:38
Cheers guys!

:goodpost:

rajs
6th August 2012, 09:08
roozhou, great tool! Any chance of adding the ability to change the sps_id to a new value? This would need to be done in all SPS and PPS of course.
Thanks!

byme
27th September 2012, 00:02
I tried it with some video
for example I have a video at 704x570

I tried to write this

ffmpeg -i xxx.mp4 -vcodec copy -acodec copy -vbsf h264_changesps=sar=16:9 xxx2.mp4

or

ffmpeg -i xxx.mp4 -vcodec copy -acodec copy -vbsf h264_changesps=sar=95:66 xxx2.mp4

but ffmpeg after enter closes without creating any video
how can I do?

foldaway
5th October 2012, 15:44
Hi roozhou,
1st: Thank you for a very useful tool!
2nd: Is there any chance of a new build against the latest ffmpeg, as there seems to be lots of bugs in the muxers & network IO which have been fixed since your last build.

Thanks

nbarzgar
20th February 2013, 06:09
Thanks, so much, roozhou!!
Tried two .avi-files with the wrong ar (h264-video) and it worked like a charm!
(Used ffmpeg-version you referred to in first post. EDIT: On Win7 x64, to boot!)
Was beginning to pull hair out, since other apparently useful tools didn't work at all!
:) :)

dx1
5th March 2013, 00:20
Well, at first I had some problems with this tool, but I figured it out.

What I did before: I converted some PAL DVD material to h264 mkv. I'm using megui and since a recent update the avs creator didn't set "global MeGUI_darx" and "global MeGUI_dary" anymore, which resulted in some h264 raw streams with an PAR of 1:1 (square pixels). We all know this looks really ugly, when the movie is supposed to haven an SAR of ~2.35. In my case I had an encoded video of 716:432 that needed an SAR of 1018:432. No problem, I thought. Just enter these values when muxing with mkvmerge gui. The resulting mkv looked perfect in mpc-hc and xbmc, but my standalone player stretched it to fullscreen and everyone was tall and slim.

MediaInfo said "Display aspect ratio 2.35:1" and "Original display aspect ratio 1.657". That seemed to be the problem with the standalone. I needed to get rid of the original display aspect ratio value. mkvmerge's editor for file headers didn't help neither did h264info. The latter corrupted the raw stream so badly, mpc-hc showed me a wobbly green and nothing more.

So, this ffmpeg build was my last hope for my problem if I didn't want to reencode the videos (four files are like this). But I had some problems with it. I thought I would have to do it like:
ffmpeg -i video.h264 -vcodec copy -vbsf h264_changesps=sar=1018:432 video2.h264
But the result was an PAR of ~3.9 -- like the original (~1.657) was multiplied with the new one (~2.35). So I calculated a little and found:
ffmpeg -i video.h264 -vcodec copy -vbsf h264_changesps=sar=614:432 (or 209:147) video2.h264
This resulted in the correct DAR/PAR/SAR of 1018:432 and played nicely enough on the standalone. There are still some minor issues with the video playback, but it will do, for tomorrow I have a day off and want to watch, not to encode.

So, thanks for this build.

KnY
5th March 2013, 21:13
What command line do I need to use if I only want to change level and leave the video and audio alone? Is it possible to just copy over the audio and video and only change the level?

Besides changing level, will it also affect the profile type, i.e. main, high? Is there an option to change the profile type in this build?

bernd_b
7th April 2013, 10:51
I only can guess it would be something like:


ffmpeg -i infile.264 -vcodec copy -an -sn -vbsf h264_changesps=level=41 outfile.264

Of course 41 would be replaced according to

level=x ---- Set level to x. (e.g. 30 for L3.0, 41 for L4.1)

bernd_b
9th April 2013, 13:46
What would be the recommended way to use this tools currently on Linux:

1) Use the win32-build linked with wine
2) patch an ffmpeg and compile it?
with the files given on page 1.

If number 2, would I have to apply the vsfilter 3697 patch only or the latest ffmpeg-git patch (rev. 31792).

Or is there already an another alternative I missed?

davidfavor
18th November 2013, 16:02
Any chance of this patch being updated to latest ffmpeg-2.1 by the original author?

If you're willing to do the update, I'll do the leg work to pitch the dev team to include this as a standard bitstream filter in the mainline code.

This set of patches is essential to all sorts of container modifications which can be done without transcoding.

A serious win for ffmpeg.

aether
14th February 2014, 22:54
Can some one please help me, I'm a newb at this and can't get it to work can some one please tell me how?

nhakobian
15th February 2014, 03:37
Can some one please help me, I'm a newb at this and can't get it to work can some one please tell me how?

Well, if you actually tell us what the problem is, maybe someone can help you out. :P

Plus if you are a "newb" there is a forum specifically for these types of questions.

aether
15th February 2014, 12:25
Well I thought it would be best to ask first before I say what the problem is. I used ffmpeg for the first time a few days ago, I got it installed and found a guide on how to use it but the problem now is that I can't get the tool to work, the file created by ffmpeg is exactly the same as the source file, so I want to make sure that what I'm doing is correct starting from the beginning. So my first question is how to install and patch the ffmpeg_git_31792 tool downloaded from this thread?

nbarzgar
16th February 2014, 14:12
Hello there,

if you really need help, in these cases you should post the
file-information (e.g. from mediainfo)

the parameters you used for ffmpeg and perhaps
file-information of the new file, in case slight changes occurred.

Otherwise there's no chance that the knowledgable people around could assist you. Billions of files/possibilities out there...

aether
17th February 2014, 17:17
Because I'm new at using ffmpeg I suspect that I did not install it correctly, so I wanted top start with that and the commandline I used is the same as the example in the first post. All I need the tool for is changing the aspect ratio of some videos I didn't convert correctly and doing it all over again would take too long.

So can you please tell me how to install the tool, do I replace the ffmpeg file in the bin folder or do I need to do some thing else?

magistral
6th November 2014, 01:13
Hi,
the following creates a file with appropriate size, the frame that opens is in the correct SAR when I set it to the number I want, but it never plays (counts up to 3-4 seconds with no video and then skips to the end).
I run it as administrator and tried to remux with no other attachments but the result is always the same.

Please tell me if I did something wrong or if there is another tool that can change SAR in bitstream as setting it in container does not work and this is not my encode.

>"./ffmpeg.exe" -i "C:\fuyu.mkv" -vcodec copy -an -vbsf
h264_changesps=sar=0:0 test.mkv
ffmpeg version N-31792-g51fb933, Copyright (c) 2000-2011 the FFmpeg developers
built on Aug 11 2011 23:13:25 with gcc 4.5.2
configuration:
libavutil 51. 11. 1 / 51. 11. 1
libavcodec 53. 10. 0 / 53. 10. 0
libavformat 53. 6. 0 / 53. 6. 0
libavdevice 53. 2. 0 / 53. 2. 0
libswscale 2. 0. 0 / 2. 0. 0
[matroska,webm @ 00388d90] max_analyze_duration 5000000 reached at 5024000
[matroska,webm @ 00388d90] Estimating duration from bitrate, this may be inaccur
ate

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (48000/
1001) -> 23.98 (48000/2002)
Input #0, matroska,webm, from 'C:\fuyu.mkv':
Duration: 00:39:00.17, start: 0.000000, bitrate: 192 kb/s
Stream #0.0(jpn): Video: h264 (High 10), yuv420p10le, 720x480 [SAR 1:1 DAR 3
:2], SAR 8:9 DAR 4:3, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0.1(jpn): Audio: [0][0][0][0] / 0x0000, 48000 Hz, stereo, 192 kb/s (
default)
File 'test.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'test.mkv':
Stream #0.0(jpn): Video: H264 / 0x34363248, yuv420p10le, 720x480 [SAR 8:9 DA
R 4:3], q=0-0, 1k tbn, 1k tbc (default)
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop, [?] for help
frame=24807 fps=24782 q=-1.0 size= 156855kB time=00:17:14.53 bitrate=1242.1kbps
frame=37530 fps=25003 q=-1.0 size= 223568kB time=00:26:05.19 bitrate=1170.1kbps
frame=49874 fps=24924 q=-1.0 size= 299866kB time=00:34:40.03 bitrate=1181.0kbps
frame=56108 fps=24843 q=-1.0 Lsize= 336144kB time=00:39:00.04 bitrate=1176.8kbp
s
video:335741kB audio:0kB global headers:0kB muxing overhead 0.119861%

>

nixo
6th November 2014, 10:39
Try using raw input/output. I find it usually works better.

--
Nikolaj

magistral
6th November 2014, 23:04
Try using raw input/output. I find it usually works better.

--
Nikolaj

That worked perfectly, thank you.

Jou
7th November 2014, 21:10
I write a bitstream filter for ffmpeg.
sar=x:y ---- Set sar to x:y, 0:0 will remove sar info


:thanks::thanks::thanks::thanks::thanks:

Thank you so much, you saved more than a day of batch of 8K video encoding which I accidentally encoded with 64:45 (as for DVB-S) instead of 1:1 (as for 3DMark).
Worked right "out of the box" and "as advertised".

directline
19th July 2016, 16:41
Hi, I know this is an old thread , I will give it a shot.

I have an UDP ts source with 1:1 aspect ratio that I will like to change to 16:9, I have tried the following command and it seems to have no effect.

ffmpeg -i udp:127.0.0.1:2001 -vcodec copy -a codec copy -vbsf h264_changesps=sar=16:9 -f mpegts udp:127.0.0.1:2002

Is this bitstreamfilter supposed to work with UDP ts ?, if so, Any Idea why it may be not working ?

Thanks for your help.

SeeMoreDigital
19th July 2016, 16:51
Hi, I know this is an old thread , I will give it a shot.

I have an UDP ts source with 1:1 aspect ratio that I will like to change to 16:9, I have tried the following command and it seems to have no effect.
What's the sources resolution?

directline
19th July 2016, 21:03
What's the sources resolution?


As reported by Media Info:

Format : MPEG-TS
File size : 9.58 MiB
Duration : 57s 545ms
Overall bit rate : 1 397 Kbps

Video
ID : 68 (0x44)
Menu ID : 1 (0x1)
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Baseline@L3.0
Format settings, CABAC : No
Format settings, ReFrames : 2 frames
Duration : 57s 545ms
Width : 704 pixels
Height : 576 pixels
Display aspect ratio : 1.222
Frame rate : 25.000 fps
Resolution : 24 bits
Colorimetry : 4:2:0
Scan type : Progressive


The source material is anamorphic, so, it should be signalled as 16:9

SeeMoreDigital
20th July 2016, 08:52
As reported by Media Info:
The source material is anamorphic, so, it should be signalled as 16:9Try using 64:45 or 16:11

directline
20th July 2016, 11:56
Tried both options and the result is the same, no change on the output.

What tool I can use in order to video the SAR info of the stream ?

I will want to be sure what is being sent on the stream.

SeeMoreDigital
20th July 2016, 12:29
Hi directline,

According to your MediaInfo file report, the 'Display Aspect Ratio' is 1.222. Given that 704 ÷ 576 = 1.2222 this would suggest that what ever method/tool you are using to change the aspect ratio signalling within the AVC video stream is not working...

Ideally it should look more like this: -
General
ID : 1 (0x1)
Complete name : \\NAS\Test Files\720(1024)x576 'Non-square Pixels' (AVC+AAC) in M2TS.m2ts
Format : BDAV
Format/Info : Blu-ray Video
File size : 10.9 MiB
Duration : 1 min
Overall bit rate mode : Variable
Overall bit rate : 1 525 kb/s
Maximum Overall bit rate : 35.5 Mb/s

Video
ID : 4113 (0x1011)
Menu ID : 1 (0x1)
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Main@L4
Format settings, CABAC : Yes
Format settings, ReFrames : 4 frames
Codec ID : 27
Duration : 1 min
Bit rate mode : Variable
Maximum bit rate : 40.0 Mb/s
Width : 720 pixels
Height : 576 pixels
Display aspect ratio : 16:9
Frame rate : 25.000 FPS
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Language : English

Reino
25th July 2016, 17:45
Seeing the amount of interest in this special FFMpeg build, even from one of FFMpeg's authors (https://trac.ffmpeg.org/ticket/2046#comment:7), can anyone explain why FFMpeg hasn't implemented this bitstreamfilter?

I've used it on a 640x360 (16:9) MP4[H.264+AAC]. A stretched video that should've been 480x360 (4:3). With -vbsf h264_changesps=sar=3:4 I got a video that MPC-BE and VLC played without any problems, but wouldn't play on my Samsung SMART TV. Since my smarttv is more picky with all sorts of media files, I begin to doubt the bitstreamfilter works according to specifications.
MP4Box's result with -par 1=3:4 my smarttv likes better and with the correct aspect ratio.

markanini
23rd October 2016, 12:49
Is there a GUI for this software?

I second this, and I don't mean to be impudent. Having used MKVToolNix spoils you, but it's clearly faster than typing out the command on every task. Perhaps we can make use of some (https://web.archive.org/web/20151030080940/http://members.home.nl/w.speek/batchenc.htm) generic launcher GUI (http://winff.org/) or write some scripts.

hello_hello
24th October 2016, 11:58
I second this, and I don't mean to be impudent. Having used MKVToolNix spoils you, but it's clearly faster than typing out the command on every task. Perhaps we can make use of some (https://web.archive.org/web/20151030080940/http://members.home.nl/w.speek/batchenc.htm) generic launcher GUI (http://winff.org/) or write some scripts.

AnotherGUI (http://www.videohelp.com/software/AnotherGUI) is another option. I use it quite a bit with ffmpeg for batch remuxing from one container to another.

directline
1st April 2017, 17:32
I have an UDP ts source with 1:1 aspect ratio that I will like to change to 16:9, I have tried the following command and it seems to have no effect.

ffmpeg -i udp:127.0.0.1:2001 -vcodec copy -a codec copy -vbsf h264_changesps=sar=16:9 -f mpegts udp:127.0.0.1:2002

Is this bitstreamfilter supposed to work with UDP ts?, if so, Any Idea why it may be not working ?


After this posts I have done more tests and I can conclude that this does not work with ts , I have done the following tests:

If I try to change the SAR of a mp4 file that is originally 4:3 SAR and stream out as 16:9 udp ts, this is the command it will do it ok.

ffmpeg -re -i capturadora.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb -vbsf h264_changesps=sar=16:11 -f mpegts udp:127.0.0.1:1235

But on the contrary if I try to read a ts file from disk and change the SAR to stream it out with this command:
ffmpeg -i capturadora.ts -vcodec copy -acodec copy -vbsf h264_changesps=sar=16:11 -f mpegts udp:127.0.0.1:1235
this will not work and the same original SAR of 4:3 will be sent out.

I tried to do it with a 4:3 stream in and it does not change the SAR either.
ffmpeg -i udp://127.0.0.1:1234 -vcodec copy -acodec copy -vbsf h264_changesps=sar=16:11 -f mpegts udp:127.0.0.1:1235

I can conclude that for whatever reason this does not work with mpeg2 transport stream, I have sent a message to the original developer but he seems not to be active in the forum anymore.

Do you have any further clue?

Thanks.

Luke M
29th May 2017, 10:50
I'm trying to use this tool to change the FPS of a .mp4, without success. No matter what options (-vbsf h264_changesps=fps=x or -muxerfps=x or -r x or all of them combined), the FPS remains unchanged.

If anyone has done this, can you give the exact command(s)? Thanks!