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 15th October 2018, 12:13   #1  |  Link
zn
Registered User
 
Join Date: Jan 2009
Posts: 88
encode 25 fps to 50 fps before merging with 50 fps (25 fps source + 50 fps source)

Is it possible to join 2 videos (2 parts), they are from the same hdtv 50 fps source, second part is untouched 50 fps, first part was re-encoded from 50 to 25 fps.
I'd like to keep second part untouched after merging, can you help me to find setting to encode 25 fps to 50 fps so I can join them with (mkvmerge, ffmpeg)

Code:
Input #0, h264, from '1.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1200k tbn, 50 tbc
Code:
Input #0, h264, from '2.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709/unknown/unknown, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 1200k tbn, 100 tbc
When trying to mkvmerge without re-encoding it didn't work:
Code:
mkvmerge -o test.mkv -A 1.mkv -A +2.ts                                                                                                                     ↑
mkvmerge v27.0.0 ('Metropolis') 64-bit
'1.mkv': Using the demultiplexer for the format 'Matroska'.
'2.ts': Using the demultiplexer for the format 'MPEG transport stream'.
'1.mkv' track 0: Using the output module for the format 'AVC/h.264'.
'2.ts' track 0: Using the output module for the format 'AVC/h.264 (unframed)'.
No append mapping was given for the file no. 1 ('2.ts'). A default mapping of 1:0:0:0 will be used instead. 
Please keep that in mind if mkvmerge aborts with an error message regardin
g invalid '--append-to' options.
Error: The track number 0 from the file '2.ts' cannot be appended to the track number 0 from the file '1.mkv'. The formats do not match.
So, I want to re-encode:
25 fps / Main@L3.1 / cabac=0 / ref=5 (mediainfo) / 'AVC/h.264'
to
50 fps / High@L3.2 / cabac=1 / ref=2 (mediainfo) / 'AVC/h.264 (unframed)' / “Format settings, GOP : M=3, N=50”,

-- To get ref=2 and cabac=1 (mediainfo):
ffmpeg -i 25fps.mkv -r 50 -refs 1 -x264opts b-pyramid=0 -crf 20 -acodec copy 50fps.mkv

-- To get GOP size(M=3) and GOP length(N=50), not sure if this correct:
-x264opts keyint=50:min-keyint=3:no-scenecut

-- To double fps:
ffmpeg -i 25.mkv -r 50 -vsync 0 -vf setpts=N/50/TB -refs 1 -x264opts b-pyramid=0:keyint=50:min-keyint=3:no-scenecut -acodec copy -crf 22 50fps.mkv

After encoding this file can be merged with untouched 50fps file, it can be played, but seeking back to first part of the video do not work, I am getting this error in mpv:
Code:
Error while decoding frame!
[ffmpeg/video] h264: illegal modification_of_pic_nums_idc 7
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
Error while decoding frame!
Other error messagewhen trying to seek back file encoded with less settings:

ffmpeg -i 25.mkv -r 50 -vsync 0 -vf setpts=N/50/TB -crf 22 50fps.mkv

Code:
Error while decoding frame!
[ffmpeg/video] h264: deblocking_filter_idc 5 out of range
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
[ffmpeg/video] h264: co located POCs unavailable

Last edited by zn; 15th October 2018 at 19:19.
zn is offline   Reply With Quote
Old 15th October 2018, 19:38   #2  |  Link
mkver
Registered User
 
Join Date: May 2016
Posts: 197
1. There are at least two ways in which H.264 can be stored: In annex B style (named so because it is defined in annex B of the H.264 standard) every "NAL Unit" (some data belonging together, like all the data from a frame) is prefixed by a start code 0x00 00 01. Care is taken that there is no pattern 0x00 00 01 at a byte-aligned position within the NAL Units and therefore these 0x00 00 01 signal the beginning of a new NAL Unit. So in order to find the boundaries of a NAL Unit one has to check for this pattern. In mp4 style (which is the way Matroska does it, too), one does things differently: Every NAL Unit is preprended with a length field (usually four bytes) that contains the length of the NAL Unit.
2. mkvmerge calls the annex B style "unframed" and the mp4 style "framed" and it has two different output modules for them. The way mkvmerge works internally means that you can't append an unframed track to a framed one. But this is not the end of the world: You can remux the transport stream to Matroska, the result is H.264 in Matroska which is framed and then you can append them with mkvmerge.
3. But here are some things you should note:
a) If you simply append the two files, you will certainly end up with a message like "The codec's private data does not match" by mkvmerge. This post contains an explanation into why this is so and what you can do about it (points 2. and 4.). (Actually, the SPS and PPS mismatch is what is causing the problems you experience when seeking back to the first part in your joined file: mpv tries to decode the first part with SPS and PPS for the second part that is simply invalid for the first part.)
b) In general you cannot expect the joint point (where you switch from the first to the second part) to be free of artifacts; this is especially true if there is a so called "open GOP" at the beginning of the second part. It should be good when the second part begins with a so called IDR frame.
mkver is offline   Reply With Quote
Old 21st October 2018, 17:35   #3  |  Link
zn
Registered User
 
Join Date: Jan 2009
Posts: 88
Thank you, it worked on my other files for merging encodes without playback error (I was having "mmco: unref short failure" error beforing using your method)
zn 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 12:08.


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