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. |
30th November 2019, 08:35 | #1 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,277
|
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" 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" 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 -> Does anyone know a way to change the PAR of such a stream without reencoding (preferably with ffmpeg)? Cu Selur Last edited by Selur; 30th November 2019 at 08:37. |
30th November 2019, 08:54 | #2 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,277
|
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" --- 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" 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 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 Last edited by Selur; 30th November 2019 at 09:19. Reason: added calls I used in the workaround |
30th November 2019, 13:51 | #3 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
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 ??? |
30th November 2019, 20:01 | #4 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,277
|
@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 |
|
|