Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: Norbert on June 01, 2016, 03:33:36 PM

Title: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: Norbert on June 01, 2016, 03:33:36 PM
Using Windows 7 or Windows 10 64-bit, and avidemux 2.6.12-64, I cut and re-encode H246 mp4 files on a daily basis. The file source is a professional online tv recorder service (save.tv) which generates files with I-frames occurring every 1 second exactly.

This is quite comfortable for good cutting-out advertisement blocks as well as additional temporary insertions by tv stations which are unwanted by me too, I delogo them as well.

When re-encoding these files with avidemux using the standard settings for H.264, I get files as result which have I-frames with
non-equal time differences between them - sometimes 5 or 4 seconds exactly, sometimes others like e.g. 3.760 or 2.920. See the following list of I-frame time data shown after using the ">>" button on a file re-encoded using MP4 Muxer with "Mpeg4 AVC (x264)" as video output:
00:00:05.400
00:00:10.400
00:00:14.600
00:00:19.600
00:00:23.360
00:00:25.280
00:00:26.640
...

Oddly additionally, despite having cut the source file exactly on I-frames, the avidemux time indicator at the bottom shows 00.00.00.040 or 00.00.00.020 at the beginning, instead of 00.00.00.000 which I would expect.

When I compare the content of the windows shown after selecting File - Information, I cannot see any differences between the input files from the provider and the result files after re-encoding - both say:
Video: H264, 1024x576, 1:1, 50.000 fps, and Audio: AAC, Stereo, 16000 Bps/125 kbps, 48000 Hz.

I've seen that after selecting Mpeg4 AVC (x264) I can press "Configure", and under "Frame" there is a section "I-frames" - but to be honest, I have no idea what and how I should change the values there to get I-frames every exactly one second. Several test runs haven't been successful.

I'd be glad if I could set the output files to the same behavior as the input files, this would make working on a result file the second time much better - if I have overseen an unwanted insertion the first time and have to re-encode the file part in question a second time, currently I have to delogo video parts that are tendentionally too long (e.g. if the unwanted insertion is 10 seconds long, I'd have a file chunk of 12 seconds max. to redo with I-frames once a second, but will likely have to redo 16-20 sec with the output file from the first run.

Is there anything I can do?
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: EEMcGee on June 02, 2016, 05:04:49 AM
     If your not trying to cut the size way down just set the output to copy instead of recode.  That would save you a lot of time and every time you recode you lose quality.  I-frames should not be set at time intervals but where the is a scene change and a lot of new information is needed to the image that has changed a lot,  P-frames when there is a more minor change in scene, and b-frames in between those.  If you put an I-frame in every second you would decrease quality and increase file size in general.  It would be trying to use P-frames where there should be I-frames which would lower quality and it would put I-frames in where they may not be needed wasting valuable bitrate.  If I am wrong on any of this somebody please correct me.  I would not consider I-frames on a time interval a good idea. 
     If you really want that though, putting the "GOP Size" setting "min 60" and "max 60" that might do it.  You would have to try it and see.  That setting is at the bottom of the "Frame" tab in X264 output "configure" settings.  GOP stands for group of pictures.
     Here is a definition from Wikipedia "In video coding, a group of pictures, or GOP structure, specifies the order in which intra- and inter-frames are arranged. The GOP is a group of successive pictures within a coded video stream. Each coded video stream consists of successive GOPs. From the pictures contained in it, the visible frames are generated. Encountering a new GOP in a compressed video stream ensures the decoder that no previous frame will be needed to decode the next ones, and is what allows fast seeking through the video."
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: Norbert on June 02, 2016, 03:02:02 PM
Quote from: EEMcGee on June 02, 2016, 05:04:49 AM
     If your not trying to cut the size way down just set the output to copy instead of recode.  That would save you a lot of time and every time you recode you lose quality.  I-frames should not be set at time intervals but where the is a scene change and a lot of new information is needed to the image that has changed a lot,  P-frames when there is a more minor change in scene, and b-frames in between those.  If you put an I-frame in every second you would decrease quality and increase file size in general.  It would be trying to use P-frames where there should be I-frames which would lower quality and it would put I-frames in where they may not be needed wasting valuable bitrate.  If I am wrong on any of this somebody please correct me.  I would not consider I-frames on a time interval a good idea. 
     If you really want that though, putting the "GOP Size" setting "min 60" and "max 60" that might do it.  You would have to try it and see.  That setting is at the bottom of the "Frame" tab in X264 output "configure" settings.  GOP stands for group of pictures.
     Here is a definition from Wikipedia "In video coding, a group of pictures, or GOP structure, specifies the order in which intra- and inter-frames are arranged. The GOP is a group of successive pictures within a coded video stream. Each coded video stream consists of successive GOPs. From the pictures contained in it, the visible frames are generated. Encountering a new GOP in a compressed video stream ensures the decoder that no previous frame will be needed to decode the next ones, and is what allows fast seeking through the video."

Thank you EEMcGee, this is very helpful to me. Now I think I understand a little bit more about the encoding details.

First checks after setting GOP size to 60 both at min and max show that the file size indeed increase, by approx. 12% in comparison to using the standard configuration. I-frames aren't set exactly to 1 sec though but sometimes a little bit more or less, for my purposes however this isn't a problem. I guess I will use this approach only where there is a good chance of necessity to recode parts of the video a second time - since I have always to use the delogo filter, and several others from time to time too, unfortunately I won't succeed by setting the output to copy. I understand with every recoding there is a quality loss which of course I would like to avoid, however I don't see a way around that if I still want to get rid of tv station logos and other unwanted artifacts. - I've grown up watching tv in the 1960s and 70s in Germany before there were logos and other annoying stuff everywhere, and obviously can't get over my history :)
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: EEMcGee on June 03, 2016, 06:08:07 AM
You could try setting the min GOP at half of your FPS rate.  That would allow it to make a seek at less than a second  when it makes more sense.  This might lead to more coding efficiency as it would allow I-frames more where there is actually a scene change.  If the seek is less a second it just makes it easier to cut on an I-frame that will be more likely to at the scene change where you want to cut anyway. 
     I would really try to do the commercial cutting and delogo or any other filtering in one shot and give the recoding as much flexibility as possible to get the best video for the size.  I can't imagine there would be much in the way of recutting or anything after you do the recode.  What do you have for hardware that you doing the work with?
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: Norbert on June 03, 2016, 08:59:38 AM
Quote from: EEMcGee on June 03, 2016, 06:08:07 AM
You could try setting the min GOP at half of your FPS rate.  That would allow it to make a seek at less than a second  when it makes more sense.  This might lead to more coding efficiency as it would allow I-frames more where there is actually a scene change.  If the seek is less a second it just makes it easier to cut on an I-frame that will be more likely to at the scene change where you want to cut anyway. 

Thank you again EEMcGee, I'll try that.

Quote
What do you have for hardware that you doing the work with?

Currently, I work on two machines concurrently in my network at home, both are Win 7 systems from 2012 with Intel i-5-2500K CPU @ 3.3GHz, 16MB RAM. It takes me usually approx. 4-5 hours a day, mostly done in the morning, to get everything of my interest processed which was broadcast on tv the evening before.

To accelerate things, I've just ordered a new machine with Intel i7-6700 4x 3.4 GHz, 32 MB RAM, 2400 MHz; I expect this one to arrive some time next week. I'll plan to set this up with Windows 10.

During the day at work, I can use a Windows 10 machine from 2013 with Intel i-5-4570K CPU @ 3.2 GHz, 16MB RAM. This one I use for anything of interest that is broadcast on tv during the day, which however isn't much as a rule.

To illustrate the processes I do a bit more: A typical file with from a tv station may have this structure -
Length of the film is 88 min, througout which the main tv logo is shown, mostly near the upper left or upper right corner. 10 seconds into the film, an insertion is created by the tv station, saying "Supported by product placements", 12 seconds long. Then for a couple of minutes everything is fine, then another insertion occurs: "Follow us on twitter #xyz" for 15 seconds. Then there may be a commercial, after the end of which you get 3 seconds ok, then "Continuing with the film named abc", for 8 seconds, then 5 seconds ok, then "Supported by product placements", 12 seconds long again. And so forth, until the end.

I have set up a (growing) collection of text files containing the data needed for the delogo filter (x,y,width,height) which I can thankfully load via File - Project Script - Run Project, named folowing the pattern tvstationnname_x.logo, productplacements.logo, twitter.logo etc.

What I found out during the first days using ADM is that the best approach to cleanse a tv-broadcast film soiled with logos and insertions like above, seems to be at first to cut off everything before the beginning and after the end, then load tvstationnname.logo, then recode the first chunk until the first unwanted insertion comes. After this first chunk is done, I delete it with cntl-x, load the next appropriate delogo project (productplacements.logo in the example above), set the end of the second chunk with (B), process again, cntl-x again, delete the productplacements logo in video-filters so that the tvstationnname logo is still active, select the next chunk until before the twitter insertion comes and set the end of this third chunk with (B), recode this, cntl-x again, and so forth.

At the end I have a number of file chunks which I only need to append in the right order, which thankfully is no problem with ADM as I just have to drop them one by one into ADM, video output after file-close is already set to copy all right, wait a minute or so and the result file w/o logos etc. is ready.

Of course the result file is only as good as my ability to always find all unwanted insertions during the preview of the file. Mostly I get them all, however sometimes I see that I have missed something only after the complete recoding is done, so I have to rework that part of the recoded file a second time.



Thank you again for your help!
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: mean on June 03, 2016, 09:18:38 AM
It's supposed to work (i.e. undo the last cut)
I might have broken it. I'll have a look.
Title: Re: [moved]How can I set I-frames to occur exactly in one-second-steps in mp4 H264 ?
Post by: Norbert on June 04, 2016, 09:10:17 AM
Quote from: mean on June 03, 2016, 09:18:38 AM
It's supposed to work (i.e. undo the last cut)
I might have broken it. I'll have a look.

Undo the last cut indeed DOES work, I checked again. Please accept my apologies, I wasn't careful enough obviously so my "By the way" remark was wrong. Sorry to have bothered you with that.