I would like to take live-captured h.264 video as an input and trim it to start in a fade up from black and end with a fade to black with as little encoding as possible. These fade in/out points may fall between I frames. It is not possible to trim at non-I frames without re-encoding.
I made a diagram:
I would like to split the input file into three parts. Part A would start at the I-Frame before point 1 and end at point 1. Part C would start at the I-Frame at point 2 and end at the next I-Frame after the fade to black. They would be re-encoded into an all I-Frame format. These two segments would be relatively short 10-30 seconds. Part B (most of the video) could just be transcoded using codec:copy.
Parts A & C would be trimmed (either automatically using black detection or manually) and then the entire video would be concatenated using ffmpeg.
I would like to use ffmpeg because that is what I'm most familiar with and the rest of my workflow uses it exclusively. What command lines would achieve this?
For the curious, here is my working command line to capture live video into encoded segments. From this point it is easy to discard unnecessary video, and re-encode segments if needed for trimming. The final step is to concatenate the segments.
ffmpeg -f dshow -rtbufsize 702000k -video_size 1920x1080 -framerate 29.97 -pixel_format uyvy422 -i video="Decklink Video Capture":audio="Decklink Audio Capture" -threads 0 -c:v libx264 -s 1280x720 -crf 18 -profile:v main -level 3.1 -pix_fmt yuv420p -c:a libvo_aacenc -b:a 128k -ac 1 -f segment -segment_time 0.01 -reset_timestamps 1 seg%02d.mp4