493: Undecipherable



-About me-


Simulating adaptive video coding

Dennis Guse

For a subjective user study on temporal effects of varying system performance, I needed to create a video with varying video encoding bandwidth, e.g. up to min 3 take 2 Mbit/s and then for 1 min 0.5 Mbit/s.

This can be easily achieved using ffmpeg/avconv:

//1. (optional) Determine keyframe position using _ffprobe_ ([see](http://superuser.com/questions/554620/how-to-get-time-stamp-of-closest-keyframe-before-a-given-timestamp-with-ffmpeg)
ffprobe -select_streams v -show_frames -v quiet VIDEO | awk -F= ' 
  /pict_type=/ { if (index($2, "I")) { i=1; } else { i=0; } } 
  /pkt_pts_time/ { if (i && ($2 >= 150)) print $2; } ' | head -n 1

//2. Encode all parts of the video
ffmpeg -i VIDEO -ss  0  -to 180 -b:v 2M  PART1
ffmpeg -i VIDEO -ss 180 -to 240 -b:v 1M PART2
ffmpeg -i VIDEO ...

//3. Paste all parts together (replace xx accordingly)
ffmpeg -i PART1 -i PART2 ... -i PARTxx -filter_complex '[0:0] [1:0] ... [xx:0] concat=n=xx:v=1 [v]' -map '[v]' -b:v 20M VIDEO_RECODED

//At this point the video encoding bandwidth should be rather big (here 20Mbit/s), so the introduced articifacts are encoded properly.

//4. Verify that video is frame identical
//If the cut timestamps are not correct, single frames might be dropped and thus audio and video get asynchronuous.
//For this cut one frame (best almost at the end with same motion) and save it for the original and the transcoded video.
//When comparing those they should look identical (especially viewing angle) except for additional coding artificats.
ffmpeg -ss 00:34:00 -t 1 -i VIDEO -f mjpeg VIDEO.jpg
ffmpeg -ss 00:34:00 -t 1 -i VIDEO_RECODED -f mjpeg VIDEO_RECODED.jpg

//5. (optional) Re-add the audio from original VIDEO
ffmpeg -i VIDEO_RECODED -i VIDEO -map 0:0 -map 1:1 -c:a copy -c:v copy