Log in

View Full Version : Modify h264 resolution in header without re-encoding


Music Fan
11th May 2022, 08:58
Hi,

I recorded a streaming in flv a while ago and the video resolution changed during the streaming.
I achieved to split the file to get 2 files, each with its own resolution, using this method (ffprobe then ffmpeg) ;
https://superuser.com/questions/1298954/how-to-split-video-files-upon-detected-change-in-resolution-ie-recorded-strea
I kept the flv container but I can change it if needed.

The problem is that the second file has the same header than the first and I'd like to correct it to make it recognizable by all players.

I can though play it with MPC-HC which opens it directly at its actual resolution, as if header was ignored, but VLC can't : it opens the file at the size of original's header resolution and displays a green image.

MediaInfo does not detect its actual resolution either.

Can ffmpeg correct it ?
Here are informations about metadata but I don't see how to change resolution ;
https://ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fmetadata
I tried the option -aspect (on the second flv) but it only added informations in the header about resolution in MediaInfo (thus there is resolution plus original resolution). It didn't make it more playable by VLC.

If I demux the second file in .h264 with ffmpeg, MediaInfo still detects only the original resolution.

I also tried My MP4Box GUI but it seems that only framerate can be modified, not resolution.

Thanks for suggestions ;)

Music Fan
18th May 2022, 13:25
If it's not possible, I will re-encode it, while my goal is generally to avoid re-encoding when no modification is done on video.
But I have to admit that x265 compression makes clearly decrease the size compared to x264, thus it becomes useful.

After splitting, I tested a re-encoding of the second part with ffmpeg, it failed : no error message but the video was gray and the original's resolution was kept instead of its actual's.

But it worked with Virtual Dub 2 which opened it directly at the good resolution :cool:
I first tested to save it in mkv as is but direct stream copy was refused for this file.

When splitting the original video with ffmpeg, it absolutely has to stay in flv to be readable by VD2 (didn't work in mkv or mp4).

Brazil2
19th May 2022, 00:32
The -aspect option of ffmpeg will change the display aspect ratio but you need to remux to MP4:

ffmpeg -i input.flv -aspect 1280:720 -c copy output.mp4

Of course replace 1280:720 with the resolution of your video. Split the video first and then apply the command line to the splitted parts.

Music Fan
19th May 2022, 08:30
Thanks but it doesn't work, the video becomes unplayable, even by MPC-HC while it plays correctly the splitted flv's.

therube
25th May 2022, 16:12
You might give Avidemux (http://avidemux.sourceforge.net/) a shot.
Use its 'Copy' options (for both audio & video, i.e., lossless).

Depending on the streams, you may need to output to mp4 (or mkv or avi or...).
(Output to flv itself is only for FLV1 & VP6.)

If output to mp4 (or...) works, you can then copy that out back to flv.
(At which point you again need to see if it still works ;-).)
(ffmpeg -i out.mp4 -c copy out.flv)

And if not Avidemux, then maybe some other utility.
(With Avidemux, I would go with the latest nightly or the 2.7.8 release [rather then the 2.8.0 release].)

Music Fan
26th May 2022, 07:53
Ok, thanks for the suggestion.
I used it years ago but it had some problems, then I discovered ffmpeg which seemed more stable.

Anyway, this problem made me discover x265's efficiency thus if I still have header's problems, I will re-encode.