Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 30th November 2019, 08:35   #1  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,905
Changing PAR in H.264 bitstream using FFmpeg

Using a file named 'h264_par_1.mp4' with the following characteristics:

h264_par_1 had:
Sampled_Width : 640
Sampled_Height : 352
Pixel aspect ratio : 1.000 <-
Display aspect ratio : 1.818
Display aspect ratio : 16:9

one can use:
Code:
ffmpeg -y -i "E:\Output\h264_par_1.mp4" -map 0:0 -vcodec copy -an -sn  -bsf:v h264_metadata=sample_aspect_ratio=2 "E:\Output\h264_par_2.mp4"
(seems to work fine with any x264 encode)
to change the PAR from 1 to 2.

h264_par_2 has:
Sampled_Width : 640
Sampled_Height : 352
Pixel aspect ratio : 2.000 <-
Display aspect ratio : 3.636
Display aspect ratio : 3.636

Problem is if the input stream has no PAR data like 'Attica The Movie - Trailer By Brass':
(which I uploaded to my GoogleDrive

Width : 1280
Width : 1 280 pixels
Height : 720
Height : 720 pixels
Pixel aspect ratio : 1.000
Display aspect ratio : 1.778
Display aspect ratio : 16:9
note: MediaInfo shows no Sampled Width/Height

Code:
ffmpeg -y -i "F:\TestClips&Co\files\MPEG-4 H.264\Attica The Movie - Trailer By Brass.mp4" -map 0:0 -vcodec copy -an -sn -bsf:v h264_metadata=sample_aspect_ratio=2 "E:\Output\test.mp4"
fails with
Code:
[AVBSFContext @ 000001bcad3b5b00] rbsp_alignment_zero_bit out of range: 1, but must be in [0,0].
[AVBSFContext @ 000001bcad3b5b00] Failed to read unit 0 (type 7).
[AVBSFContext @ 000001bcad3b5b00] Failed to read extradata.
Error initializing bitstream filter: h264_metadata
My current guess is that the original stream has no explicit PAR (/ Sampled Width/Height) info which is why ffmpegs bitstream filter can't modify those values and change the PAR.

-> Does anyone know a way to change the PAR of such a stream without reencoding (preferably with ffmpeg)?

Cu Selur
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..

Last edited by Selur; 30th November 2019 at 08:37.
Selur is offline   Reply With Quote
Old 30th November 2019, 08:54   #2  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,905
I found a workaround by first remuxing to mkv using mkvtoolnix and then using
Code:
ffmpeg -y -i "E:\Output\Attica The Movie - Trailer By Brass.mkv" -map 0:0 -vcodec copy -an -sn -bsf:v h264_metadata=sample_aspect_ratio=2 "E:\Output\test.mp4"
still would be nice to do this in one go with ffmpeg.

---
for completeness here the calls I used in my workaround:
1. extracting the video stream
Code:
MP4Box -raw 1 "F:\TESTCL~1\files\MPEG-4~1.264\ATTICA~1.MP4" -out "E:\Temp\Attica The Movie - Trailer By Brass_new_09_16_09_7710_01.264"
2. muxing to mkv
Code:
mkvmerge --ui-language en -o "E:\Output\Attica The Movie - Trailer By Brass.mkv" -d 0 --default-track 0:yes --default-duration 0:30/1fps --aspect-ratio-factor 0:1/1 --no-chapters --compression -1:none --forced-track 0:yes --no-audio --no-subtitles "E:\Temp\Attica The Movie - Trailer By Brass_new_09_16_09_7710_01.264
3. adjusting the PAR
Code:
ffmpeg -y -i "E:\Output\Attica The Movie - Trailer By Brass.mkv" -map 0:0 -vcodec copy -an -sn -bsf:v h264_metadata=sample_aspect_ratio=2 "E:\Output\test.mp4"

Cu Selur
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..

Last edited by Selur; 30th November 2019 at 09:19. Reason: added calls I used in the workaround
Selur is offline   Reply With Quote
Old 30th November 2019, 13:51   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,266
Some related links here

https://forum.videohelp.com/threads/...ut-re-encoding

http://superuser.com/questions/61894...sung-camcorder

http://forum.videohelp.com/threads/3...out-reencoding

http://forum.doom9.org/showthread.php?t=152419
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 30th November 2019, 20:01   #4  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,905
@StainlessS: Thanks, sadly
MP4Box only sets the container not the stream PAR, the ffmpeg version in the thread you linked to is dated and the stuff it can do is replaced with the bitstream filters in ffmpeg, see: https://ffmpeg.org/ffmpeg-bitstream-filters.html
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..
Selur is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:18.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.